Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku - how to start job worker (delayed job)?

I have some miniapp that use delayed_job. On my localhost everything works fine, but when I deploy my app to Heroku and click on the link that should be executed by delayed_job, so nothing happen, the "task" is just saved into the table delayed_job.

In this article on heroku blog is written, that the task from delayed_job table is executed, when is run this command rake jobs:work.

But how can I run this command? Where should be the command placed? In the code, or from terminal console?

like image 784
user984621 Avatar asked Apr 02 '12 19:04

user984621


People also ask

How do you restart a delayed job?

Restart Delayed Job on deploy You must remove that one now if you have it. It basically does the same thing that we will add now but without using upstart. We will now create a new file that will host our start, stop and restart tasks. Create a file at lib/capistrano/tasks/delayed_job.

How does a delayed job work?

Delayed Job uses your database as a queue to process background jobs. If your app has a high database load using DelayedJob may not be a good background queueing library for your app. To get started using Delayed Job you need to configure your application and then run a worker process in your app.

How do I know if my job is running late?

The most simple way to check whether delayed_job is running or not, is to check at locked_by field. This field will contain the worker or process locking/processing the job. Running Delayed::Job. where('locked_by is not null') will give you some results, if there are jobs running.


2 Answers

If you are running the Cedar stack, run the following from the terminal console:

heroku run rake jobs:work

If you are running the older stacks (Bamboo, Aspen, etc.):

heroku rake jobs:work

see: https://devcenter.heroku.com/articles/rake

According to the delayed_job documentation, you can also start a worker programmatically:

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'

Delayed::Worker.new.start 
like image 108
Carlos Ramirez III Avatar answered Sep 20 '22 12:09

Carlos Ramirez III


You should use a Procfile to scpecify the commands for your dynos. For example you would have something like this in your Procfile:

appDir/Procfile

web:     bundle exec rails server -p $PORT 
worker:  bundle exec rake jobs:work

To use this on your development machine, you should use Foreman, it's all explained at the docs.

https://devcenter.heroku.com/articles/procfile

like image 28
Ismael Avatar answered Sep 21 '22 12:09

Ismael