beanstalk extensions for ruote (a ruby workflow engine)
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
doc
lib
spec
test
.gitignore
CHANGELOG.txt
CREDITS.txt
Gemfile
LICENSE.txt
README.md
Rakefile
TODO.txt
readme.rdoc
ruote-beanstalk.gemspec
serve.rb

README.md

ruote-beanstalk

Beanstalk extensions for ruote (a Ruby workflow engine).

Beanstalk is a simple, fast, workqueue service.

ruote-beanstalk provides two things, first a ParticipantProxy / Receiver pair, second a ruote storage implementation.

The ParticipantProxy / Receiver pair is about emitting workitems to a Beanstalk queue/tube and listening/receiving them back. Workers can connect to the Beanstalk queue, receive workitems, do some work and then (optionally) send the updated workitem back to the ruote system.

Ruote::Beanstalk::Storage is a storage implementation for ruote. Workers and engines can connect over Beanstalk to a shared storage.

The storage listens to a Beanstalk queue where it receives storage orders that it conveys to a FsStorage instance.

(Initially I tried to use Beanstalk for msgs and schedules as well, but since you can't delete a delayed message in Beanstalk (as of now), I fell back to using Beanstalk as middleware, it's slightly slower, but much simpler and robust).

rdoc : http://ruote.rubyforge.org/ruote-beanstalk_rdoc/

usage

Ruote::Beanstalk::ParticipantProxy and Receiver

Registering a Beanstalk participant :

  @engine.register_participant(
    'alpha',
    Ruote::Beanstalk::ParticipantProxy,
    'beanstalk' => '127.0.0.1:11300',
    'tube' => 'ruote-workitems')

Binding a listener to a storage or an engine :

  Ruote::Beanstalk::Receiver.new(
    engine, '127.0.0.1:11300', 'tube' => 'ruote-incoming')

      # or

  Ruote::Beanstalk::Receiver.new(
    storage, '127.0.0.1:11300', 'tube' => 'ruote-incoming')

The receiver manages a thread that listens to incoming messages and feeds them to ruote via the engine or directly via a storage.

Ruote::Beanstalk::Storage

There are two modes in which Storage can be used :

  • bound to a remote storage (client)
  • bound to the physical storage (server)

There should always be at least 1 server and 1 client.

Beanstalk is the intermediary.

client

Pass a string of the form host:port and a hash of options :

  Ruote::Beanstalk::Storage.new('127.0.0.1:11300', opts)

Wrapped in an engine + worker :

  engine = Ruote::Engine.new(
    Ruote::Worker.new(
      Ruote::Beanstalk::Storage.new('127.0.0.1:11300', opts)))

server

This piece of ruby starts a Beanstalk instance (:fork => true) and starts a BsStorage 'server' coupled to an embedded FsStorage :

  require 'ruote/beanstalk'

  Ruote::Beanstalk::Storage.new(':11300', 'ruote_work', :fork => true)

running tests

Ruote::Beanstalk::ParticipantProxy and Receiver

Simply do

  ruby test/test.rb

in your ruote-beanstalk/ directory.

Ruote::Beanstalk::Storage

assuming you have

  ruote/
  ruote-beanstalk/

In a separate terminal, go to ruote-beanstalk/ and launch

  ruby serve.rb

To launch a beanstalkd + fs storage couple, then run unit or functional tests

  • unit tests :

get into ruote/ and do

  ruby test/unit/storage.rb -- --beanstalk
  • functional tests :

get into ruote/ and do

  ruby test/functional/test.rb -- --beanstalk

license

MIT

links

feedback

many thanks to

  • the beanstalk authors and contributors