Ruby‎ > ‎Getting Started‎ > ‎

SimpleWorker on Heroku

Heroku Stack Setup

SimpleWorker require Ruby 1.9+, but Heroku defaults to Ruby 1.8 by default so you either need to set the stack you want when creating your Heroku project or migrate to a more recent stack (easy either way).

If creating a new Heroku project, use:

$ heroku create my_app --stack cedar

Of if you already have an app on Heroku, use:

$ heroku stack:migrate cedar

More info on the available Heroku stacks.

Installing the SimpleWorker Add-on

To use simple_worker on Heroku, install the simple_worker add-on:

$ heroku addons:add simple_worker

Then follow the SimpleWorker add-on link for your application in the heroku UI to get your credentials.

Configuring SimpleWorker

Once you have your credentials for SimpleWorker, simply add the following to development.rb:

ENV['SIMPLE_WORKER_TOKEN'] = 'YOUR TOKEN'
ENV['SIMPLE_WORKER_PROJECT_ID'] = 'YOUR PROJECT ID'

You don't need to add this to production.rb as Heroku will do that automatically.

Tokens can be found on the API Tokens tab under the Account link. Your project ID can be found on the projects page

Then create a file at config/initializers/simple_worker.rb and put the following into it:

SimpleWorker.configure do |config|
  config.token = ENV['SIMPLE_WORKER_TOKEN']
  config.project_id = ENV['SIMPLE_WORKER_PROJECT_ID']
  # Use the line below if you're using an ActiveRecord database
  config.database = Rails.configuration.database_configuration[Rails.env]
end

That's all you need to do. Now it's time to make your first worker, follow the SimpleWorker on Rails instructions here.

SimpleWorker and Heroku SharedDB

At present, Heroku does not allow external access to their shared database. We're working with them to get access to allow SimpleWorker jobs to connect to them but we're not there yet.

If the shared database is too limiting, we suggest switching to a dedicated database or using something like Xeround, Amazon's RDS, MongoLab or MongoHQ, or one of the other add-on databases. Ping us if you have any questions here.

Comments