From 4d894ee8534e4803fc3033d253817928b8c66573 Mon Sep 17 00:00:00 2001 From: Saurabh Nanda Date: Fri, 6 Oct 2023 12:16:29 +0000 Subject: [PATCH] using withTransaction --- src/OddJobs/Job.hs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/OddJobs/Job.hs b/src/OddJobs/Job.hs index ae1a624..8eb97f8 100644 --- a/src/OddJobs/Job.hs +++ b/src/OddJobs/Job.hs @@ -836,14 +836,14 @@ scheduleJob conn tname payload runAt = do type ResourceList = [(ResourceId, Int)] -createJobWithResources - :: ToJSON p - => Connection - -> TableName - -> ResourceCfg - -> p - -> ResourceList - -> IO Job +createJobWithResources :: + ToJSON p => + Connection -> + TableName -> + ResourceCfg -> + p -> + ResourceList -> + IO Job createJobWithResources conn tname resCfg payload resources = do t <- getCurrentTime scheduleJobWithResources conn tname resCfg payload resources t @@ -857,10 +857,9 @@ scheduleJobWithResources -> ResourceList -> UTCTime -> IO Job -scheduleJobWithResources conn tname ResourceCfg{..} payload resources runAt = do +scheduleJobWithResources conn tname ResourceCfg{..} payload resources runAt = PGS.withTransaction conn $ do -- We insert everything in a single transaction to delay @NOTIFY@ calls, -- so a job isn't picked up before its resources are inserted. - PGS.begin conn let args = ( tname, runAt, Queued, toJSON payload, Nothing :: Maybe Value, 0 :: Int, Nothing :: Maybe Text, Nothing :: Maybe Text ) queryFormatter = toS <$> PGS.formatQuery conn createJobQuery args rs <- PGS.query conn createJobQuery args @@ -874,8 +873,6 @@ scheduleJobWithResources conn tname ResourceCfg{..} payload resources runAt = do void $ PGS.execute conn ensureResource (resCfgResourceTable, rawResourceId resourceId, resCfgDefaultLimit) void $ PGS.execute conn registerResourceUsage (resCfgUsageTable, jobId job, rawResourceId resourceId, usage) - PGS.commit conn - pure job -- getRunnerEnv :: (HasJobRunner m) => m RunnerEnv