From 997092f26aea8f30a663711172124a21d9b36cbb Mon Sep 17 00:00:00 2001 From: PumpkinSeed Date: Mon, 2 Sep 2024 13:40:06 +0200 Subject: [PATCH] Add JobCleaner timeout dynamically --- client.go | 6 ++++++ internal/maintenance/job_cleaner.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/client.go b/client.go index 4aa69df9..844999eb 100644 --- a/client.go +++ b/client.go @@ -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. @@ -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 diff --git a/internal/maintenance/job_cleaner.go b/internal/maintenance/job_cleaner.go index 3a9d70b2..0433e591 100644 --- a/internal/maintenance/job_cleaner.go +++ b/internal/maintenance/job_cleaner.go @@ -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. @@ -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 { @@ -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,