0.0
No commit activity in last 3 years
No release in over 3 years
Resque participant/receiver pair for Ruote
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0

Runtime

>= 0
 Project Readme

Build Status Coverage Status Code Climate Dependency Status

Ruote::Resque

Synopsis

Ruote::Resque allows a Ruote engine to delegates the work of it's participants to Resque workers.

Common use cases include:

  • You run a lot of jobs and need the reliability of Resque to process your jobs
  • You have a Resque system you need to integrate with
  • You want a separation of concerns between process orchestration and actual execution

How it works

  • The library uses a specific Resque queue for message passing.
  • Participants are empty shells that just queue jobs to Resque, and the job itself replies (via an after_perform hook) with the mutated workitem.
  • Under the hood, a thread polls the reply queue every five seconds for new replies.
  • When a reply is received, the process continues with the new workitem.

Note that:

  • Ruote is not needed as a dependency on the Resque side.
  • Error handling is supported on both sides (exceptions show up both on the Resque failure backend and in ruote-kit)

Usage

Set Up

Inside your Ruote instance

Add to your Ruote instance gemfile :

# The version released on RubyGems is old and not supported.
# Note that ruote is not a hard dependency of ruote-resque,
# to allow for lightweight use as a client (see below)
gem 'ruote', :git => 'git://github.com/jmettraux/ruote.git'
gem 'ruote-resque'

Then when booting your engine do this :

require 'ruote/resque'

# Run the poller thread.
Ruote::Resque::Receiver.new(dashboard)

Inside your Resque worker instance

Add to your Resque worker instance gemfile :

gem 'ruote-resque', :require => false

Then when booting your worker do this :

# You should not require the full library inside your worker, the client will suffice
require 'ruote/resque/client'

Participants

# Inside your worker, add Ruote::Resque::Job to your jobs
class MyAwesomeJob
  extend Ruote::Resque::Job

  @queue = :my_queue

  def self.perform(workitem)
    workitem['fields']['be_awesome'] = true
  end
end

# Inside your Ruote instance
Ruote::Resque.register(dashboard) do
  be_awesome 'MyAwesomeJob', :my_queue
end

There are two other ways to register participants:

Ruote::Resque.register(dashboard) do
  participant 'be_awesome', 'MyAwesomeJob', :my_queue
end

# OR (not recommended)

dashboard.register_participant 'be_awesome', Ruote::Resque::Participant, :class => 'MyAwesomeJob', :queue => :my_queue

Note that you can pass options to the participant:

Ruote::Resque.register(dashboard) do
  be_awesome 'MyAwesomeJob', :my_queue, :forget => true
end

Configuration

# Configure the library (optional, default values shown)
# You should duplicate this configuration on both
# your Ruote instance and your Resque instance
Ruote::Resque.configure do |config|
  config.reply_queue = :ruote_replies
  config.logger = Logger.new(STDOUT).tap { |log| log.level = Logger::INFO }
  config.interval = 5
end

# Override the default error handler (optional, but recommended. Default is to log at ERROR level)
# Do this in your Ruote instance
class Ruote::Resque::Receiver
  def handle_error(e)
    MyErrorHandler.handle(e)
  end
end

Requirements

A functional installation of Ruote and Resque is needed. Note that at the time of writing the release of Ruote on rubygems is very old and not supported. Use it from git.

ruote-resque has been tested on Ruby 1.8+.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Do some changes
  4. Run the tests (bundle exec rspec)
  5. Commit your changes (git commit -am 'Add some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create new Pull Request

Changelog

  • June 23, 2013: 0.1.0 release
    • Initial release