Multiple delayed job processes starting same job

耗尽温柔 提交于 2019-12-05 05:19:52

We've run about 60 million jobs through delayed job with 12 workers and never had a report of this. Whats the SQL that your delayed job worker is running? Are you using a gem that is changing the locking behavior of postgres?

Here is what the DJ sql looks like for me:

UPDATE "delayed_jobs" SET locked_at = '2014-05-02 21:16:35.419748', locked_by =
'host:whatever.local pid:4729' WHERE id IN (SELECT id FROM "delayed_jobs" 
WHERE ((run_at <= '2014-05-02 21:16:35.415923' 
AND (locked_at IS NULL OR locked_at < '2014-05-02 17:16:35.415947') 
OR locked_by = 'host:whatever.local pid:4729') AND failed_at IS NULL) 
ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) RETURNING *

Do you have locking problems with any other code? Could you try running two rails console sessions and doing this:

Console Session 1:

User.find(1).with_lock do sleep(10); puts "worker 1 done" end

Console Session 2:

User.find(1).with_lock do sleep(1); puts "worker 2 done" end

Start both those at the same time and if 2 end before 1, you've got a locking problem more general that delayed job.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!