-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
engine/cleanupmgr: Migrate shifts to job queue (#4192)
* cleanup: implement context-aware sleep and cleanup manager functionality * cleanup: format code for consistency in alert store initialization * cleanup: remove unused ConfigSource field from SetupArgs struct * cleanup: refactor alert cleanup logic and add shift cleanup functionality * cleanup: refactor alert cleanup logic to use whileWork for better control flow * cleanup: add comment * cleanup: remove unused cleanup statements from DB and update logic * test: refactor alert auto-close and cleanup tests for improved reliability * fix: update ShiftArgs Kind to reflect cleanup-manager-shifts
- Loading branch information
1 parent
5be8cf0
commit b79c639
Showing
5 changed files
with
170 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cleanupmanager | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
|
||
"github.com/riverqueue/river" | ||
"github.com/target/goalert/config" | ||
"github.com/target/goalert/gadb" | ||
) | ||
|
||
type ShiftArgs struct{} | ||
|
||
func (ShiftArgs) Kind() string { return "cleanup-manager-shifts" } | ||
|
||
// CleanupShifts will automatically cleanup old shift and override records. | ||
func (db *DB) CleanupShifts(ctx context.Context, j *river.Job[ShiftArgs]) error { | ||
cfg := config.FromContext(ctx) | ||
if cfg.Maintenance.ScheduleCleanupDays <= 0 { | ||
return nil | ||
} | ||
|
||
err := db.whileWork(ctx, func(ctx context.Context, tx *sql.Tx) (done bool, err error) { | ||
count, err := gadb.New(tx).CleanupMgrDeleteOldScheduleShifts(ctx, int64(cfg.Maintenance.ScheduleCleanupDays)) | ||
if err != nil { | ||
return false, fmt.Errorf("delete old shifts: %w", err) | ||
} | ||
return count < 100, nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = db.whileWork(ctx, func(ctx context.Context, tx *sql.Tx) (done bool, err error) { | ||
count, err := gadb.New(tx).CleanupMgrDeleteOldOverrides(ctx, int64(cfg.Maintenance.ScheduleCleanupDays)) | ||
if err != nil { | ||
return false, fmt.Errorf("delete old overrides: %w", err) | ||
} | ||
return count < 100, nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = db.whileWork(ctx, func(ctx context.Context, tx *sql.Tx) (done bool, err error) { | ||
count, err := gadb.New(tx).CleanupMgrDeleteOldStepShifts(ctx, int64(cfg.Maintenance.ScheduleCleanupDays)) | ||
if err != nil { | ||
return false, fmt.Errorf("delete old step shifts: %w", err) | ||
} | ||
return count < 100, nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.