ruby - How resque checks when to run a job? -
i have found resque:
and can see can schedule delayed job. question is, how check delayed jobs? if have 5000 delayed jobs in 1 month time, hope doesn't check every 10 seconds delayed jobs.
so how being done?
it not have check delayed jobs. maintains sorted set in redis, jobs being sorted scheduled time. see code at:
https://github.com/elucid/resque-delayed/blob/master/lib/resque-delayed/resque-delayed.rb
each time daemon awakes, first item of set needs checked (using zrangebyscore command). daemon fetches relevant jobs 1 one, until polling query returns no result, sleeps again.
performance further improved fetching jobs n n. implemented using server-side lua script polling query:
local res = redis.call('zrangebyscore',keys[1], "-inf", argv[1], 'limit', 0, 10 ) if #res > 0 redis.call( 'zremrangebyrank', keys[1], 0, #res-1 ) return res else return false end
in 1 roundtrip, script gets 10 jobs (if available), , delete them zset. better 11 zrangebyscore , 10 zrem, required resque-delayed.