Skip to content
Eric Draut edited this page Sep 29, 2016 · 9 revisions

An industrial-strength background worker system for Rails using RabbitMQ

Submit a Job

The submit method in it's basic form takes a Ruby class, a method name as a symbol, and an array of arguments to be passed to the method. You can run any method in the background, it doesn't need to be blessed as an asynchronous method.

ConeyIsland.submit(Account, :do_something_slow, args: [@stuff,@other_things])
#more options available, see docs

If you want to make *_async methods available and set class-level defaults, include the Performer module.

class Person < ActiveRecord::Base
  include ConeyIsland::Performer
  set_background_defaults(timeout: 60, work_queue: 'my_slow_queue')

  def self.refresh_all_social_profiles
    #iterate over people to be refreshed here
  end

  def refresh_social_profile(facebook_only: false, twitter_only: false)
    #go out to the network and get fresh social data
  end
end

person = Person.first
person.refresh_social_profile_async(facebook_only: true)

See more options for submitting jobs.

Install It

In your gemfile

gem 'coney_island'

Configure It

ConeyIsland.config = {
    amqp_connection: {host: '127.0.0.1'},
    carousels: {
      default: { prefetch_count: 3 },
      cyclone: { prefetch_count: 3 },
      boardwalk: { prefetch_count: 1, worker_count: 2 }
    },
    log_level: 0,
    log: 'log/coney_island.log',
    notifier_service: 'Honeybadger'
  }

For a detailed explanation of configuration options, see here.

Don't forget that RabbitMQ has an awesome web dashboard that runs on your server so you can see what's going on with your jobs.

Install RabbitMQ

This is dependent on your environment. For Mac OSX we use homebrew, which makes installation super-simple. bash brew install rabbitmq. On Heroku we use RabbitMQ Bigwig, which can be installed like any other add-on for Heroku. If you're on EC2, see here. General instructions can be found here.

nb. Once you've installed RabbitMQ, you need to put the connection info in your ConeyIsland config as shown here. For a vanilla, local installation, the line in the config example above works. For other environments see here.

ActiveJob

Yep, ConeyIsland has a built-in ActiveJob adapter, so if ActiveJob excites you, go for it.

All the Things

Clone this wiki locally