@@ -142,7 +142,7 @@ class (MonadUnliftIO m, MonadBaseControl IO m) => HasJobRunner m where
142 getConcurrencyControl :: m ConcurrencyControl
142 getConcurrencyControl :: m ConcurrencyControl
143 log :: LogLevel -> LogEvent -> m ()
143 log :: LogLevel -> LogEvent -> m ()
144 getDefaultJobTimeout :: m Seconds
144 getDefaultJobTimeout :: m Seconds
145−
145+ getDefaultRetryBackoff :: Int -> m Seconds
147-- $logging
147-- $logging
@@ -195,6 +195,10 @@ instance HasJobRunner RunnerM where
196 getDefaultJobTimeout = cfgDefaultJobTimeout . envConfig <$> ask
196 getDefaultJobTimeout = cfgDefaultJobTimeout . envConfig <$> ask
198+ getDefaultRetryBackoff attempts = do
199+ retryFn <- cfgDefaultRetryBackoff . envConfig <$> ask
200+ liftIO $ retryFn attempts
198-- | Start the job-runner in the /current/ thread, i.e. you'll need to use
202-- | Start the job-runner in the /current/ thread, i.e. you'll need to use
199-- 'forkIO' or 'async' manually, if you want the job-runner to run in the
203-- 'forkIO' or 'async' manually, if you want the job-runner to run in the
200-- background. Consider using 'OddJobs.Cli' to rapidly build your own
204-- background. Consider using 'OddJobs.Cli' to rapidly build your own
@@ -410,11 +414,12 @@ runJob jid = do
410 then ( Failed, FailPermanent, LevelError )
414 then ( Failed, FailPermanent, LevelError )
411 else ( Retry, FailWithRetry, LevelWarn )
415 else ( Retry, FailWithRetry, LevelWarn )
412 t <- liftIO getCurrentTime
416 t <- liftIO getCurrentTime
417+ backoffInSeconds <- getDefaultRetryBackoff jobAttempts
413 newJob <- saveJob job{ jobStatus=newStatus
418 newJob <- saveJob job{ jobStatus=newStatus
414 , jobLockedBy=Nothing
419 , jobLockedBy=Nothing
415 , jobLockedAt=Nothing
420 , jobLockedAt=Nothing
416 , jobLastError=(Just $ toJSON $ show e) -- TODO: convert errors to json properly
421 , jobLastError=(Just $ toJSON $ show e) -- TODO: convert errors to json properly
417− , jobRunAt=(addUTCTime (fromIntegral $ (2::Int) ^ jobAttempts) t)
422+ , jobRunAt=(addUTCTime (fromIntegral $ unSeconds backoffInSeconds) t)
419 case fromException e :: Maybe TimeoutException of
424 case fromException e :: Maybe TimeoutException of
420 Nothing -> log logLevel $ LogJobFailed newJob e failureMode runTime
425 Nothing -> log logLevel $ LogJobFailed newJob e failureMode runTime