title: Running delayed jobs on Heroku for free
body: <p><strong>Is it possible to run delayed jobs on Heroku for free?</strong></p>
  
  <p>I'm trying to use <code>delayed_job_active_record</code> on Heroku. However, it requires a <code>worker dyno</code> and it would cost money if I turned this dyno on for full time.</p>
  
  <p>I thought using Unicorn and making its workers run delayed jobs instead of the Heroku worker, would cost nothing, while successfully running all the jobs. However, Unicorn workers do not seem to start "working" automatically.</p>
  
  <p>I have the following in my <strong>Procfile</strong>.</p>
  
  <pre><code>web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
  worker: bundle exec rake jobs:work
  </code></pre>
  
  <p>and the following in my <strong>unicorn.rb</strong></p>
  
  <pre><code>worker_processes 3
  timeout 30
  preload_app true
  
  before_fork do |server, worker|
    # Replace with MongoDB or whatever
    if defined?(ActiveRecord::Base)
      ActiveRecord::Base.connection.disconnect!
      Rails.logger.info('Disconnected from ActiveRecord')
    end
  
    # If you are using Redis but not Resque, change this
    if defined?(Resque)
      Resque.redis.quit
      Rails.logger.info('Disconnected from Redis')
    end
  
    sleep 1
  end
  
  after_fork do |server, worker|
    # Replace with MongoDB or whatever
    if defined?(ActiveRecord::Base)
      ActiveRecord::Base.establish_connection
      Rails.logger.info('Connected to ActiveRecord')
    end
  
    # If you are using Redis but not Resque, change this
    if defined?(Resque)
      Resque.redis = ENV['REDIS_URI']
      Rails.logger.info('Connected to Redis')
    end
  end
  </code></pre>
  
  <p>Delayed jobs only seem to work when I scale the Heroku worker from 0 to 1.
  Again, is it not possible to use Unicorn workers instead of Heroku worker to do the delayed jobs?</p>
  
  <p>Do I have to use a gem like <code>workless</code> to run delayed jobs on Heroku for free? (<a href="https://stackoverflow.com/questions/11625662/running-delayed-job-worker-on-heroku">reference</a>)</p>