refactor(scheduler): Add statusThreshold parameter to job.Run

The scheduler monitors running jobs to make sure they are not hung. If
the status of a running job does not change after a duration (the
interruptThreshold in the scheduler), the scheduler kills the job. This
change passes the scheduler's interruptThreshold to the job when it
calls Run() on the job.
This commit is contained in:
Michael Gaffney committed 2024-10-25 10:25:51 -04:00
1 parent 50ab600519
commit 9354a4ebcf
27 files changed
+87 -80

No files matched your search

+1 -1
View File
@@ -78,7 +78,7 @@ func (r *rotateRootsJob) Status() scheduler.JobStatus {
}
// Run executes the job by calling the rotateRoots domain function
func (r *rotateRootsJob) Run(ctx context.Context) error {
func (r *rotateRootsJob) Run(ctx context.Context, _ time.Duration) error {
const op = "server.(rotateRootsJob).Run"
_, err := server.RotateRoots(ctx, r.workerAuthRepo, nodeenrollment.WithCertificateLifetime(r.certificateLifetime))
+2 -2
View File
@@ -105,7 +105,7 @@ func TestRotateRootsJob(t *testing.T) {
assert.Equal(time.Hour, nextRun)
// Run job and ensure rotation was performed
err = got.Run(ctx)
err = got.Run(ctx, 0)
require.NoError(err)
require.Equal(1, got.totalRotates)
rootIds, err = workerAuthRepo.List(ctx, (*types.RootCertificate)(nil))
@@ -127,6 +127,6 @@ func TestRotateRootsJobFailure(t *testing.T) {
got, err := newRotateRootsJob(ctx, &db.Db{}, &db.Db{}, kmsCache)
require.NoError(err)
err = got.Run(ctx)
err = got.Run(ctx, 0)
require.Error(err)
}
@@ -35,7 +35,7 @@ func (usb *upsertWorkerStorageBucketJob) Status() scheduler.JobStatus { return s
// Run performs the required work depending on the implementation.
// The context is used to notify the job that it should exit early.
func (usb *upsertWorkerStorageBucketJob) Run(_ context.Context) error { return nil }
func (usb *upsertWorkerStorageBucketJob) Run(ctx context.Context, _ time.Duration) error { return nil }
// NextRunIn returns the duration until the next job run should be scheduled.
// Upsert Worker Storage Bucket will run every 24 hours unless we know there are