require 'resque/tasks' require 'resque_scheduler/tasks' # Scheduler needs very little cpu, just start it with a worker. desc "schedule and work, so we only need 1 dyno" task :schedule_and_work do if Process.fork sh "rake environment resque:work" else sh "rake resque:scheduler" Process.wait end end
This is interesting and thanks for sharing. I’m newish to scheduling jobs on Heroku. Where does this set of code sit? Which file?
Thanks!
e.g. Rakefile or lib/tasks/heroku.rake
I have a the following code as well. Do I need it still with this?
task :work do
ENV[‘QUEUE’] = ‘*’
end
Nevermind, I obviously do. Since this just launches the work task OR the scheduler.
If I launch more workers- does this launch that many more schedulers? Or will it always keep only one scheduler up?
It starts multiple, not sure if that is safe (does it schedule a job multiple times ?), also maybe schedulers die if there already is a scheduler running,
so you could make this more complicated by cheching if a scheduler is running or not, or check/make sure the multiple schedulers are safe to run
Would this impact this setup? http://stackoverflow.com/questions/41537142/heroku-procfile-resque-puma-rails-5-resque-scheduler-setup
Yes, you would only have the worker line (as rake schedule_and_work) and not the scheduler line.
So this “worker: bundle exec rake resque:work COUNT=1 QUEUE=*” would change to “worker: bundle exe rake schedule_and_work COUNT=1 QUEUE=*” ?
Would you be willing to add this to stack overflow too, I want to make sure you get credit for this? Also, I assume I delete the scheduler reference in the procfile correct?
Thank you for your help btw, I am trying to find 2 options. One now, and one for growth so I want to make sure I have the setup in place.
Yep, that would work … remove scheduler and later when you scale you can split these 2 up again.
I just updated the SO post. Can you confirm that matches the format you use. I greatly appreciate this as I was battling this for awhile now.
Thank you for checking the SO post. Did you want to leave an answer for credit?
Nah, got enough imaginary internet points 😉
Sounds good. Thank you so much for helping me with that. I appreciate it.