diff --git a/src/OddJobs/ConfigBuilder.hs b/src/OddJobs/ConfigBuilder.hs index 14c0208..6d87184 100644 --- a/src/OddJobs/ConfigBuilder.hs +++ b/src/OddJobs/ConfigBuilder.hs @@ -370,19 +370,19 @@ defaultImmediateJobDeletion Job{jobStatus} = -- x { cfgDelayedJobDeletion = Just (defaultDelayedJobDeletion tname 7) } -- @ defaultDelayedJobDeletion :: - (Show d, Num d) => TableName -> -- ^ DB table which holds your jobs. Ref: 'cfgTableName' - d -> - -- ^ Number of days after which successful, failed, and cancelled jobs - -- should be deleted from the table + String -> + -- ^ Time intterval after which successful, failed, and cancelled jobs + -- should be deleted from the table. __NOTE:__ This needs to be expressed + -- as an actual PostgreSQL interval, such as @"7 days"@ or @"12 hours"@ PGS.Connection -> -- ^ the postgres connection that will be provided to this function, -- to be able to execute the @DELETE@ statement. IO Int64 -- ^ number of rows\/jobs deleted defaultDelayedJobDeletion tname d conn = - PGS.execute conn qry (tname, PGS.In statusList, show d <> " days") + PGS.execute conn qry (tname, PGS.In statusList, d) where -- this function has been deliberately written like this to ensure that whenever a new Status is added/removed -- one is forced to update this list and decide what is to be done about the new Status diff --git a/test/Test.hs b/test/Test.hs index 67d987d..aa7535c 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -382,9 +382,9 @@ testJobScheduling appPool jobPool = testCase "job scheduling" $ do delaySeconds (Job.defaultPollingInterval + Seconds 2) assertJobIdStatus conn tname logRef "Job had a runAt date in the past. It should have been successful by now" Job.Success jobId -testJobDeletion appPool jobPool = testCase "job failure" $ do +testJobDeletion appPool jobPool = testCase "job immediae deletion" $ do withRandomTable jobPool $ \tname -> do - withNamedJobMonitor tname jobPool (\cfg -> cfg { Job.cfgDelayedJobDeletion = Just $ Job.defaultDelayedJobDeletion tname pinterval, Job.cfgDefaultMaxAttempts = 3 }) $ \_logRef -> do + withNamedJobMonitor tname jobPool (\cfg -> cfg { Job.cfgDelayedJobDeletion = Just $ Job.defaultDelayedJobDeletion tname pinterval, Job.cfgDefaultMaxAttempts = 2 }) $ \_logRef -> do Pool.withResource appPool $ \conn -> do let assertDeletedJob msg jid = @@ -394,17 +394,17 @@ testJobDeletion appPool jobPool = testCase "job failure" $ do successJob <- Job.createJob conn tname (PayloadSucceed 0) failJob <- Job.createJob conn tname (PayloadAlwaysFail 0) - delaySeconds Job.defaultPollingInterval + delaySeconds (Job.defaultPollingInterval * 3) assertDeletedJob "Expecting successful job to be immediately deleted" (jobId successJob) j <- ensureJobId conn tname (jobId failJob) assertEqual "Exepcting job to be in Failed status" Job.Failed (jobStatus j) - delaySeconds (Job.defaultPollingInterval * 3) + delaySeconds (Job.defaultPollingInterval * 4) assertDeletedJob "Expecting failed job to be deleted after adequate delay" (jobId failJob) where - pinterval = 3 * fromIntegral (Job.unSeconds Job.defaultPollingInterval) / (24*60*60 :: Float) + pinterval = show (Job.unSeconds Job.defaultPollingInterval) <> " seconds" testJobFailure appPool jobPool = testCase "job failure" $ do withNewJobMonitor jobPool $ \tname _logRef -> do