Skip to content

Commit

Permalink
feat: Query for changes after db row deletion
Browse files Browse the repository at this point in the history
* Emit log in debug mode on how many rows deleted

Signed-off-by: Mahendra Paipuri <[email protected]>
  • Loading branch information
mahendrapaipuri committed Jan 4, 2024
1 parent 9cd5314 commit d492685
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/jobstats/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,21 @@ func (j *jobStatsDB) vacuumDB() error {

// Delete old entries in DB
func (j *jobStatsDB) deleteOldJobs(tx *sql.Tx) error {
deleteSQLCmd := fmt.Sprintf(
deleteRowQuery := fmt.Sprintf(
"DELETE FROM %s WHERE Start <= date('now', '-%d day')",
j.jobstatDBTable,
int(j.retentionPeriod.Hours()/24),
)
_, err := tx.Exec(deleteSQLCmd)
_, err := tx.Exec(deleteRowQuery)
if err != nil {
level.Error(j.logger).Log("msg", "Failed to delete old jobs", "err", err)
return err
}

// Get changes
var rowsDeleted int
_ = tx.QueryRow("SELECT changes();").Scan(&rowsDeleted)
level.Debug(j.logger).Log("msg", "Queried for changes after deletion", "rowsDeleted", rowsDeleted)
return nil
}

Expand Down

0 comments on commit d492685

Please sign in to comment.