ruby-on-railsherokuresquepumaresque-scheduler

Using Resque, Puma and Scheduler together on Heroku


After reviewing numerous guides I would like to confirm my setup. Right now my procfile looks like:

web: bundle exec puma -C config/puma.rb config.ru
resque: TERM_CHILD=1 RESQUE_TERM_TIMEOUT=10 QUEUES=* bundle exec rake resque:work
worker: bundle exec rake resque:work COUNT=1 QUEUE=*
scheduler: bundle exec rake resque:scheduler

...and in Heroku:

enter image description here

...and my rake resque setup task:

require 'resque'
require 'resque/tasks'
require 'resque/scheduler/tasks'

# http://jademind.com/blog/posts/enable-immediate-log-messages-of-resque-workers/
namespace :resque do
  desc 'Initialize Resque environment'
  task setup: :environment do
    ENV['QUEUE'] ||= '*'
    Resque.logger.level = Logger::INFO
  end

  task scheduler_setup: :environment
end

desc 'Alias for resque:work'
task 'jobs:work' => 'resque:work'

So here are my questions:

  1. Do I need both a Resque and a worker configuration in my procfile?
  2. Do I need to have a separate dyno for the scheduler and the worker? This means 3 total dynos?

Update

I came across this posting which I am giving a try https://grosser.it/2012/04/14/resque-scheduler-on-heroku-without-extra-workers/. The goal is to be able to optionally use the 2 free dynos for my web and workers and scheduler. Once the application grows I want to break them out into their own dynos.


Solution

  • From the blog post I found

    He mentioned to role with this now...

    web: bundle exec puma -C config/puma.rb config.ru
    worker: bundle exe rake schedule_and_work COUNT=1 QUEUE=* TERM_CHILD=1 RESQUE_TERM_TIMEOUT=10
    

    ..and upgrade to this once we need more dynos...

    web: bundle exec puma -C config/puma.rb config.ru
    resque: TERM_CHILD=1 RESQUE_TERM_TIMEOUT=10 QUEUES=* bundle exec rake resque:work
    worker: bundle exec rake resque:work
    scheduler: bundle exec rake resque:scheduler
    

    This will allow us to use a web dyno until we want to pay for full time scheduler dynos.