@@ -65,24 +65,24 @@ main = do
65#if MIN_VERSION_resource_pool(0,3,0)
65#if MIN_VERSION_resource_pool(0,3,0)
66 createAppPool = Pool.newPool $ Pool.PoolConfig
66 createAppPool = Pool.newPool $ Pool.PoolConfig
67 (PGS.connect connInfo) -- create a new resource
67 (PGS.connect connInfo) -- create a new resource
68− (PGS.close) -- destroy resource
68+ PGS.close -- destroy resource
69 (fromRational 10) -- number of seconds unused resources are kept around
69 (fromRational 10) -- number of seconds unused resources are kept around
71 createJobPool = Pool.newPool $ Pool.PoolConfig
71 createJobPool = Pool.newPool $ Pool.PoolConfig
72 (PGS.connect connInfo) -- create a new resource
72 (PGS.connect connInfo) -- create a new resource
73− (PGS.close) -- destroy resource
73+ PGS.close -- destroy resource
74 (fromRational 10) -- number of seconds unused resources are kept around
74 (fromRational 10) -- number of seconds unused resources are kept around
77 createAppPool = Pool.createPool
77 createAppPool = Pool.createPool
78 (PGS.connect connInfo) -- create a new resource
78 (PGS.connect connInfo) -- create a new resource
79− (PGS.close) -- destroy resource
79+ PGS.close -- destroy resource
80 1 -- stripes
80 1 -- stripes
81 (fromRational 10) -- number of seconds unused resources are kept around
81 (fromRational 10) -- number of seconds unused resources are kept around
83 createJobPool = Pool.createPool
83 createJobPool = Pool.createPool
84 (PGS.connect connInfo) -- create a new resource
84 (PGS.connect connInfo) -- create a new resource
85− (PGS.close) -- destroy resource
85+ PGS.close -- destroy resource
86 1 -- stripes
86 1 -- stripes
87 (fromRational 10) -- number of seconds unused resources are kept around
87 (fromRational 10) -- number of seconds unused resources are kept around
@@ -139,15 +139,15 @@ testPayload :: Value
139testPayload = toJSON (10 :: Int)
139testPayload = toJSON (10 :: Int)
141jobRunner :: Job.Job -> IO ()
141jobRunner :: Job.Job -> IO ()
142−jobRunner Job{jobPayload, jobAttempts} = case (fromJSON jobPayload) of
142+jobRunner Job{jobPayload, jobAttempts} = case fromJSON jobPayload of
143 Aeson.Error e -> error e
143 Aeson.Error e -> error e
144 Success (j :: JobPayload) ->
144 Success (j :: JobPayload) ->
145 let recur pload idx = case pload of
145 let recur pload idx = case pload of
146− PayloadAlwaysFail delay -> (delaySeconds delay) >> (error $ "Forced error after " <> show delay <> " seconds")
146+ PayloadAlwaysFail delay -> delaySeconds delay >> (error $ "Forced error after " <> show delay <> " seconds")
147 PayloadSucceed delay -> void $ delaySeconds delay
147 PayloadSucceed delay -> void $ delaySeconds delay
148 PayloadFail delay innerpload -> if idx<jobAttempts
148 PayloadFail delay innerpload -> if idx<jobAttempts
149 then recur innerpload (idx + 1)
149 then recur innerpload (idx + 1)
150− else (delaySeconds delay) >> (error $ "Forced error after " <> show delay <> " seconds. step=" <> show idx)
150+ else delaySeconds delay >> (error $ "Forced error after " <> show delay <> " seconds. step=" <> show idx)
151 PayloadThrowStringException s -> throwString s
151 PayloadThrowStringException s -> throwString s
152 PayloadThrowDivideByZero -> seq (1 `div` 0 :: Integer) (pure ())
152 PayloadThrowDivideByZero -> seq (1 `div` 0 :: Integer) (pure ())
153 in recur j 0
153 in recur j 0
@@ -176,7 +176,7 @@ logEventToJob le = case le of
176 Job.LogWebUIRequest -> Nothing
176 Job.LogWebUIRequest -> Nothing
177 Job.LogText _ -> Nothing
177 Job.LogText _ -> Nothing
179−assertJobIdStatus :: (HasCallStack)
179+assertJobIdStatus :: HasCallStack
180 => Connection
180 => Connection
181 -> Job.TableName
181 -> Job.TableName
182 -> IORef [Job.LogEvent]
182 -> IORef [Job.LogEvent]
@@ -190,13 +190,13 @@ assertJobIdStatus conn tname logRef msg st jid = do
190 case st of
190 case st of
191 Job.Success ->
191 Job.Success ->
192 assertBool (msg <> ": Success event not found in job-logs for JobId=" <> show jid) $
192 assertBool (msg <> ": Success event not found in job-logs for JobId=" <> show jid) $
193− (flip DL.any) logs $ \case
193+ flip DL.any logs $ \case
194 Job.LogJobSuccess j _ -> jid == Job.jobId j
194 Job.LogJobSuccess j _ -> jid == Job.jobId j
195 _ -> False
195 _ -> False
197 Job.Queued ->
197 Job.Queued ->
198 assertBool (msg <> ": Not expecting to find a queued job in the the job-logs JobId=" <> show jid) $
198 assertBool (msg <> ": Not expecting to find a queued job in the the job-logs JobId=" <> show jid) $
199− not $ (flip DL.any) logs $ \case
199+ not $ flip DL.any logs $ \case
200 Job.LogJobStart j -> jid == Job.jobId j
200 Job.LogJobStart j -> jid == Job.jobId j
201 Job.LogJobSuccess j _ -> jid == Job.jobId j
201 Job.LogJobSuccess j _ -> jid == Job.jobId j
202 Job.LogJobFailed j _ _ _ -> jid == Job.jobId j
202 Job.LogJobFailed j _ _ _ -> jid == Job.jobId j
@@ -207,19 +207,19 @@ assertJobIdStatus conn tname logRef msg st jid = do
208 Job.Failed ->
208 Job.Failed ->
209 assertBool (msg <> ": Failed event not found in job-logs for JobId=" <> show jid) $
209 assertBool (msg <> ": Failed event not found in job-logs for JobId=" <> show jid) $
210− (flip DL.any) logs $ \case
210+ flip DL.any logs $ \case
211 Job.LogJobFailed j _ _ _ -> jid == Job.jobId j
211 Job.LogJobFailed j _ _ _ -> jid == Job.jobId j
212 _ -> False
212 _ -> False
214 Job.Retry ->
214 Job.Retry ->
215 assertBool (msg <> ": Failed event not found in job-logs for JobId=" <> show jid) $
215 assertBool (msg <> ": Failed event not found in job-logs for JobId=" <> show jid) $
216− (flip DL.any) logs $ \case
216+ flip DL.any logs $ \case
217 Job.LogJobFailed j _ _ _ -> jid == Job.jobId j
217 Job.LogJobFailed j _ _ _ -> jid == Job.jobId j
218 _ -> False
218 _ -> False
220 Job.Locked ->
220 Job.Locked ->
221 assertBool (msg <> ": Start event should be present in the log for a locked job JobId=" <> show jid) $
221 assertBool (msg <> ": Start event should be present in the log for a locked job JobId=" <> show jid) $
222− (flip DL.any) logs $ \case
222+ flip DL.any logs $ \case
223 Job.LogJobStart j -> jid == Job.jobId j
223 Job.LogJobStart j -> jid == Job.jobId j
224 _ -> False
224 _ -> False
@@ -228,16 +228,16 @@ assertJobIdStatus conn tname logRef msg st jid = do
228 Nothing -> assertFailure $ "Not expecting job to be deleted. JobId=" <> show jid
228 Nothing -> assertFailure $ "Not expecting job to be deleted. JobId=" <> show jid
229 Just (Job{jobStatus}) -> assertEqual msg st jobStatus
229 Just (Job{jobStatus}) -> assertEqual msg st jobStatus
231−ensureJobId :: (HasCallStack) => Connection -> Job.TableName -> JobId -> IO Job
231+ensureJobId :: HasCallStack => Connection -> Job.TableName -> JobId -> IO Job
232ensureJobId conn tname jid = Job.findJobByIdIO conn tname jid >>= \case
232ensureJobId conn tname jid = Job.findJobByIdIO conn tname jid >>= \case
233 Nothing -> error $ "Not expecting job to be deleted. JobId=" <> show jid
233 Nothing -> error $ "Not expecting job to be deleted. JobId=" <> show jid
234 Just j -> pure j
234 Just j -> pure j
236-- withRandomTable :: (MonadIO m) => Pool Connection -> (Job.TableName -> m a) -> m a
236-- withRandomTable :: (MonadIO m) => Pool Connection -> (Job.TableName -> m a) -> m a
237withRandomTable jobPool action = do
237withRandomTable jobPool action = do
238− (tname :: Job.TableName) <- liftIO ((fromString . ("jobs_" <>)) <$> (replicateM 10 (R.randomRIO ('a', 'z'))))
238+ (tname :: Job.TableName) <- liftIO (fromString . ("jobs_" <>) <$> replicateM 10 (R.randomRIO ('a', 'z')))
240− ((Pool.withResource jobPool $ \conn -> (liftIO $ Migrations.createJobTable conn tname)) >> (action tname))
240+ ((Pool.withResource jobPool $ \conn -> liftIO $ Migrations.createJobTable conn tname) >> action tname)
241 (Pool.withResource jobPool $ \conn -> liftIO $ void $ PGS.execute conn "drop table if exists ?" (Only tname))
241 (Pool.withResource jobPool $ \conn -> liftIO $ void $ PGS.execute conn "drop table if exists ?" (Only tname))
243testMaxAttempts :: Int
243testMaxAttempts :: Int
@@ -253,7 +253,7 @@ withNamedJobMonitor tname jobPool cfgFn actualTest = do
253 tcache <- newTimeCache simpleTimeFormat'
253 tcache <- newTimeCache simpleTimeFormat'
254 withTimedFastLogger tcache LogNone $ \tlogger -> do
254 withTimedFastLogger tcache LogNone $ \tlogger -> do
255 let flogger logLevel logEvent = do
255 let flogger logLevel logEvent = do
256− tlogger $ \t -> toLogStr t <> " | " <> (Job.defaultLogStr Job.defaultJobType logLevel logEvent)
256+ tlogger $ \t -> toLogStr t <> " | " <> Job.defaultLogStr Job.defaultJobType logLevel logEvent
257 atomicModifyIORef' logRef (\logs -> (logEvent:logs, ()))
257 atomicModifyIORef' logRef (\logs -> (logEvent:logs, ()))
258 cfg = Job.mkConfig flogger tname jobPool Job.UnlimitedConcurrentJobs jobRunner (\cfg' -> cfgFn $ cfg'{Job.cfgDefaultMaxAttempts=testMaxAttempts})
258 cfg = Job.mkConfig flogger tname jobPool Job.UnlimitedConcurrentJobs jobRunner (\cfg' -> cfgFn $ cfg'{Job.cfgDefaultMaxAttempts=testMaxAttempts})
259 withAsync (Job.startJobRunner cfg) (const $ actualTest logRef)
259 withAsync (Job.startJobRunner cfg) (const $ actualTest logRef)
@@ -263,7 +263,7 @@ payloadGen = Gen.recursive Gen.choice nonRecursive recursive
264 nonRecursive = [ PayloadAlwaysFail <$> Gen.element [1, 2, 3]
264 nonRecursive = [ PayloadAlwaysFail <$> Gen.element [1, 2, 3]
265 , PayloadSucceed <$> Gen.element [1, 2, 3]]
265 , PayloadSucceed <$> Gen.element [1, 2, 3]]
266− recursive = [ PayloadFail <$> (Gen.element [1, 2, 3]) <*> payloadGen ]
266+ recursive = [ PayloadFail <$> Gen.element [1, 2, 3] <*> payloadGen ]
268testJobCreation appPool jobPool = testCase "job creation" $ do
268testJobCreation appPool jobPool = testCase "job creation" $ do
269 withNewJobMonitor jobPool $ \tname logRef -> do
269 withNewJobMonitor jobPool $ \tname logRef -> do
@@ -282,7 +282,7 @@ testEnsureShutdown appPool jobPool = testCase "ensure shutdown" $ do
282 scheduleJob tname = withNamedJobMonitor tname jobPool Prelude.id $ \logRef -> do
282 scheduleJob tname = withNamedJobMonitor tname jobPool Prelude.id $ \logRef -> do
283 t <- getCurrentTime
283 t <- getCurrentTime
284 Pool.withResource appPool $ \conn -> do
284 Pool.withResource appPool $ \conn -> do
285− Job{jobId} <- Job.scheduleJob conn tname (PayloadSucceed 0) (addUTCTime (fromIntegral (2 * (unSeconds Job.defaultPollingInterval))) t)
285+ Job{jobId} <- Job.scheduleJob conn tname (PayloadSucceed 0) (addUTCTime (fromIntegral (2 * unSeconds Job.defaultPollingInterval)) t)
286 assertJobIdStatus conn tname logRef "Job is scheduled in future, should still be queueud" Job.Queued jobId
286 assertJobIdStatus conn tname logRef "Job is scheduled in future, should still be queueud" Job.Queued jobId
287 pure (jobId, logRef)
287 pure (jobId, logRef)
@@ -331,15 +331,15 @@ testJobScheduling appPool jobPool = testCase "job scheduling" $ do
331 job@Job{jobId} <- Job.scheduleJob conn tname (PayloadSucceed 0) (addUTCTime (fromIntegral (3600 :: Integer)) t)
331 job@Job{jobId} <- Job.scheduleJob conn tname (PayloadSucceed 0) (addUTCTime (fromIntegral (3600 :: Integer)) t)
332 delaySeconds $ Seconds 2
332 delaySeconds $ Seconds 2
333 assertJobIdStatus conn tname logRef "Job is scheduled in the future. It should NOT have been successful by now" Job.Queued jobId
333 assertJobIdStatus conn tname logRef "Job is scheduled in the future. It should NOT have been successful by now" Job.Queued jobId
334− _ <- Job.saveJobIO conn tname job{jobRunAt = (addUTCTime (fromIntegral (-1 :: Integer)) t)}
334+ _ <- Job.saveJobIO conn tname job{jobRunAt = addUTCTime (fromIntegral (-1 :: Integer)) t}
335− delaySeconds (Job.defaultPollingInterval + (Seconds 2))
335+ delaySeconds (Job.defaultPollingInterval + Seconds 2)
336 assertJobIdStatus conn tname logRef "Job had a runAt date in the past. It should have been successful by now" Job.Success jobId
336 assertJobIdStatus conn tname logRef "Job had a runAt date in the past. It should have been successful by now" Job.Success jobId
338testJobFailure appPool jobPool = testCase "job failure" $ do
338testJobFailure appPool jobPool = testCase "job failure" $ do
339 withNewJobMonitor jobPool $ \tname _logRef -> do
339 withNewJobMonitor jobPool $ \tname _logRef -> do
340 Pool.withResource appPool $ \conn -> do
340 Pool.withResource appPool $ \conn -> do
341 Job{jobId} <- Job.createJob conn tname (PayloadAlwaysFail 0)
341 Job{jobId} <- Job.createJob conn tname (PayloadAlwaysFail 0)
342− delaySeconds $ (calculateRetryDelay testMaxAttempts) + (Seconds 3)
342+ delaySeconds $ calculateRetryDelay testMaxAttempts + Seconds 3
343 Job{jobAttempts, jobStatus} <- ensureJobId conn tname jobId
343 Job{jobAttempts, jobStatus} <- ensureJobId conn tname jobId
344 assertEqual "Exepcting job to be in Failed status" Job.Failed jobStatus
344 assertEqual "Exepcting job to be in Failed status" Job.Failed jobStatus
345 assertEqual ("Expecting job attempts to be 3. Found " <> show jobAttempts) 3 jobAttempts
345 assertEqual ("Expecting job attempts to be 3. Found " <> show jobAttempts) 3 jobAttempts
@@ -531,7 +531,7 @@ timeGen t d = do
531 pure $ Time.timeSince t (fromInteger i) u d
531 pure $ Time.timeSince t (fromInteger i) u d
533anyTimeGen :: MonadGen m => UTCTime -> m UTCTime
533anyTimeGen :: MonadGen m => UTCTime -> m UTCTime
534−anyTimeGen t = (Gen.element (enumFrom Time.Ago)) >>= (timeGen t)
534+anyTimeGen t = Gen.element (enumFrom Time.Ago) >>= timeGen t
536futureTimeGen :: MonadGen m => UTCTime -> m UTCTime
536futureTimeGen :: MonadGen m => UTCTime -> m UTCTime
537futureTimeGen t = timeGen t Time.FromThat
537futureTimeGen t = timeGen t Time.FromThat
@@ -584,7 +584,7 @@ genFilter t = do
584 Nothing -> Gen.maybe (anyTimeGen t)
584 Nothing -> Gen.maybe (anyTimeGen t)
585 Just x -> Gen.maybe (futureTimeGen x)
585 Just x -> Gen.maybe (futureTimeGen x)
586 orderClause <- Gen.maybe ((,) <$> (Gen.element $ enumFrom Web.OrdCreatedAt) <*> (Gen.element $ enumFrom Web.Asc))
586 orderClause <- Gen.maybe ((,) <$> (Gen.element $ enumFrom Web.OrdCreatedAt) <*> (Gen.element $ enumFrom Web.Asc))
587− limitOffset <- Gen.maybe ((,) <$> (Gen.int (Range.constant 5 10)) <*> (Gen.int (Range.constant 0 30)))
587+ limitOffset <- Gen.maybe ((,) <$> Gen.int (Range.constant 5 10) <*> Gen.int (Range.constant 0 30))
588 runAfter <- Gen.maybe (futureTimeGen t)
588 runAfter <- Gen.maybe (futureTimeGen t)
589 pure Web.blankFilter
589 pure Web.blankFilter
590 { filterStatuses = statuses
590 { filterStatuses = statuses
@@ -602,21 +602,21 @@ filterJobs :: Filter -> [Job] -> [Job]
602filterJobs Web.Filter{filterStatuses, filterCreatedAfter, filterCreatedBefore, filterUpdatedAfter, filterUpdatedBefore, filterOrder, filterPage, filterRunAfter} js =
602filterJobs Web.Filter{filterStatuses, filterCreatedAfter, filterCreatedBefore, filterUpdatedAfter, filterUpdatedBefore, filterOrder, filterPage, filterRunAfter} js =
603 applyLimitOffset $
603 applyLimitOffset $
604 applyOrdering (fromMaybe (Web.OrdUpdatedAt, Web.Desc) filterOrder) $
604 applyOrdering (fromMaybe (Web.OrdUpdatedAt, Web.Desc) filterOrder) $
605− (flip DL.filter) js $ \j -> (filterByStatus j) &&
605+ flip DL.filter js $ \j -> filterByStatus j &&
606− (filterByCreatedAfter j) &&
606+ filterByCreatedAfter j &&
607− (filterByCreatedBefore j) &&
607+ filterByCreatedBefore j &&
608− (filterByUpdatedAfter j) &&
608+ filterByUpdatedAfter j &&
609− (filterByUpdatedBefore j) &&
609+ filterByUpdatedBefore j &&
610− (filterByRunAfter j)
610+ filterByRunAfter j
612− applyLimitOffset = maybe Prelude.id (\(l, o) -> (Prelude.take l). (Prelude.drop o)) filterPage
612+ applyLimitOffset = maybe Prelude.id (\(l, o) -> Prelude.take l . Prelude.drop o) filterPage
614 applyOrdering (fld, dir) lst =
614 applyOrdering (fld, dir) lst =
615 let comparer = resultOrder $ case fld of
615 let comparer = resultOrder $ case fld of
616− Web.OrdCreatedAt -> (comparing jobCreatedAt)
616+ Web.OrdCreatedAt -> comparing jobCreatedAt
617− Web.OrdUpdatedAt -> (comparing jobUpdatedAt)
617+ Web.OrdUpdatedAt -> comparing jobUpdatedAt
618− Web.OrdLockedAt -> (comparing jobLockedAt)
618+ Web.OrdLockedAt -> comparing jobLockedAt
619− Web.OrdStatus -> (comparing jobStatus)
619+ Web.OrdStatus -> comparing jobStatus
620 Web.OrdJobType -> comparing Job.defaultJobType
620 Web.OrdJobType -> comparing Job.defaultJobType
621 resultOrder fn x y = case fn x y of
621 resultOrder fn x y = case fn x y of
622 EQ -> compare (Down $ jobId x) (Down $ jobId y)
622 EQ -> compare (Down $ jobId x) (Down $ jobId y)