Skip to content

Commit

Permalink
Merge pull request #1918 from digitallyinduced/worker-refactor
Browse files Browse the repository at this point in the history
Worker: Fixed poller not scheduling concurrent jobs
  • Loading branch information
mpscholten authored Feb 21, 2024
2 parents ed5ecd9 + 7b8befc commit 92af5ce
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion IHP/Job/Queue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ pollForJob tableName pollInterval onNewJob = do
forever do
count :: Int <- sqlQueryScalar query params

when (count > 0) (Concurrent.putMVar onNewJob JobAvailable)
when (count > 0) do
-- For every job we send one signal to the job workers
-- This way we use full concurrency when we find multiple jobs
-- that haven't been picked up by the PGListener
forEach [0..count] \_ -> do
Concurrent.putMVar onNewJob JobAvailable

-- Add up to 2 seconds of jitter to avoid all job queues polling at the same time
jitter <- Random.randomRIO (0, 2000000)
Expand Down

0 comments on commit 92af5ce

Please sign in to comment.