简体   繁体   中英

Run background-job every hour for n number of times(ruby on rails)

I am using resque for job scheduling. I want to run a job every 1 hour and for N times only. I also want to pass count in the job as argument

for example:

i=0
50.times do 
   every 1.hour, roles: [:whenever_cron] do
     runner "Resque.enqueue(SomeJob, i+1)"
   end 
end

How can I do this?

Note : - I don't want to run 50 jobs every hour. I want to run 1 job 50 times

Scheduling syntax is for recurring jobs. Those that happen over and over again, until the end of times.

For single-shot jobs, you enqueue them, with an optional delay (which is what you need here). So you can just enqueue the whole batch of your jobs all at once, with 1 hour increments:

1.upto(50).each do |x|
  Resque.enqueue_in(x.hours, SomeJob)
end 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM