Skip to content

Commit

Permalink
Add JobCleaner timeout dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
PumpkinSeed committed Sep 2, 2024
1 parent 8669cbc commit 997092f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ type Config struct {
// Defaults to 7 days.
DiscardedJobRetentionPeriod time.Duration

// JobCleanerTimeout is the timeout of the job cleaner's runner.
//
// Defaults to 30 seconds.
JobCleanerTimeout time.Duration

// ErrorHandler can be configured to be invoked in case of an error or panic
// occurring in a job. This is often useful for logging and exception
// tracking, but can also be used to customize retry behavior.
Expand Down Expand Up @@ -558,6 +563,7 @@ func NewClient[TTx any](driver riverdriver.Driver[TTx], config *Config) (*Client
CancelledJobRetentionPeriod: config.CancelledJobRetentionPeriod,
CompletedJobRetentionPeriod: config.CompletedJobRetentionPeriod,
DiscardedJobRetentionPeriod: config.DiscardedJobRetentionPeriod,
JobCleanerTimeout: config.JobCleanerTimeout,
}, driver.GetExecutor())
maintenanceServices = append(maintenanceServices, jobCleaner)
client.testSignals.jobCleaner = &jobCleaner.TestSignals
Expand Down
5 changes: 5 additions & 0 deletions internal/maintenance/job_cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
CompletedJobRetentionPeriodDefault = 24 * time.Hour
DiscardedJobRetentionPeriodDefault = 7 * 24 * time.Hour
JobCleanerIntervalDefault = 30 * time.Second
JobCleanerTimeoutDefault = 30 * time.Second
)

// Test-only properties.
Expand All @@ -48,6 +49,9 @@ type JobCleanerConfig struct {

// Interval is the amount of time to wait between runs of the cleaner.
Interval time.Duration

// JobCleanerTimeout is the timeout of the job cleaner runner.
JobCleanerTimeout time.Duration
}

func (c *JobCleanerConfig) mustValidate() *JobCleanerConfig {
Expand Down Expand Up @@ -88,6 +92,7 @@ func NewJobCleaner(archetype *baseservice.Archetype, config *JobCleanerConfig, e
CompletedJobRetentionPeriod: valutil.ValOrDefault(config.CompletedJobRetentionPeriod, CompletedJobRetentionPeriodDefault),
DiscardedJobRetentionPeriod: valutil.ValOrDefault(config.DiscardedJobRetentionPeriod, DiscardedJobRetentionPeriodDefault),
Interval: valutil.ValOrDefault(config.Interval, JobCleanerIntervalDefault),
JobCleanerTimeout: valutil.ValOrDefault(config.JobCleanerTimeout, JobCleanerTimeoutDefault),
}).mustValidate(),

batchSize: BatchSizeDefault,
Expand Down

0 comments on commit 997092f

Please sign in to comment.