Using Delayed Job (DJ) to Handle Background Tasks
Delayed Job let you run background tasks with your Rails application. It 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 project and you should have a look to Sidekiq or Resque.
delayed_job to your Project
To get started using Delayed Job you need to configure your application.
# With MySQL or PostgreSQL gem 'delayed_job_active_record' # OR if your using MongoDB gem 'delayed_job_mongoid'
bundle install to install the gem.
If your using MySQL or PostgreSQL, you also need to apply migrations to your database:
rails generate delayed_job:active_record rake db:migrate
That’s it your application is ready, you can find more information on their Github page
Adding ‘delayedjob’ container type in your Procfile
delayed_job has been installed, you need to add a new type of containers
in your application which will actually start delayed_job. Add the following
line to the Procfile of
your project. Create the file if it doesn’t exist.
delayedjob: bin/delayed_job run
Do not use
delayed_job startto start the process.
startstarts the process in background and our crash detection system will consider it as crashed, it has to run in the foreground thanks to the
All you have to do now is to write your jobs by following DJ documentation and deploy your code:
git add Gemfile Gemfile.lock Procfile git commit -m "Add delayed job" git push scalingo master
The process won’t be started directly, but by going to the dashboard of your
application or by running the
scalingo ps command, you’ll see that’s the new
container type is present, just scale it to 1 to start it.