-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
engine/cleanupmgr: finalize migration to job queue for cleanup operat…
…ions (#4218) * 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 * feat: add periodic jobs for schedule data cleanup and update queries * feat: add workers for cleanup of shifts and schedule data * fix: update periodic job interval for schedule data cleanup to 24 hours * feat: add logging support to cleanup manager and engine initialization * refactor: streamline schedule data cleanup by extracting user validation and shift trimming logic * feat: add logging for schedule data updates in cleanup manager * refactor: remove unnecessary checks for empty shifts in user and shift trimming functions * refactor: enhance schedule data cleanup by improving user validation and logging * refactor: improve formatting of schedule data update call in cleanup manager * docs: add comment to clarify cleanupData function purpose in schedule data management * feat: add CleanupAlertLogs function to manage alert log entries for deleted alerts * refactor: remove unused cleanupAlertLogs statement and related logic from cleanup manager * feat: implement timeout for CleanupAlertLogs worker to handle longer job durations * refactor: rename cleanupDays to more descriptive staleThresholdDays in cleanup manager functions * docs: enhance comment for CleanupMgrScheduleData to clarify last_cleanup_at usage * engine/cleanupmgr: refactor schedule data cleanup logic and add job for looking up schedules needing cleanup * engine/cleanupmgr: implement alert log cleanup job scheduling and refactor related queries * engine/initriver: remove unused noopWorker type * engine/cleanupmgr: rename LookForWorkArgs types for consistency * feat(cleanupmanager): implement API key cleanup functionality * feat(cleanupmanager): add periodic job for API key cleanup and remove unused update logic * fix merge issue * fix merge issue * regen * fix arg type
- Loading branch information
1 parent
b8acc00
commit 1ac513f
Showing
6 changed files
with
152 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cleanupmanager | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
|
||
"github.com/riverqueue/river" | ||
"github.com/target/goalert/config" | ||
"github.com/target/goalert/gadb" | ||
) | ||
|
||
type APIKeysArgs struct{} | ||
|
||
func (APIKeysArgs) Kind() string { return "cleanup-manager-api-keys" } | ||
|
||
// CleanupAPIKeys will revoke access to the API from unused tokens, including both user sessions and calendar subscriptions. | ||
func (db *DB) CleanupAPIKeys(ctx context.Context, j *river.Job[APIKeysArgs]) error { | ||
err := db.whileWork(ctx, func(ctx context.Context, tx *sql.Tx) (done bool, err error) { | ||
// After 30 days, the token is no longer valid, so delete it. | ||
// | ||
// This is defined by how the keyring system works for session signing, and is not influenced by the APIKeyExpireDays config. | ||
count, err := gadb.New(tx).CleanupMgrDeleteOldSessions(ctx, 30) | ||
if err != nil { | ||
return false, fmt.Errorf("delete old user sessions: %w", err) | ||
} | ||
return count < 100, nil | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cfg := config.FromContext(ctx) | ||
if cfg.Maintenance.APIKeyExpireDays <= 0 { | ||
return nil | ||
} | ||
|
||
err = db.whileWork(ctx, func(ctx context.Context, tx *sql.Tx) (done bool, err error) { | ||
count, err := gadb.New(tx).CleanupMgrDisableOldCalSub(ctx, int32(cfg.Maintenance.APIKeyExpireDays)) | ||
if err != nil { | ||
return false, fmt.Errorf("disable unused calsub keys: %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
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 was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.