Fast and easy task runner for Rails. Got work?
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 28 commits behind barttenbrinke:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
generators/worker_queue_migration
lib/worker_queue
spec
tasks
LICENSE
README
init.rb

README

Bart ten Brinke - Nedap healthcare - 2008

-----------
Description
-----------
As I found other Rails background project to unstable, complex or too memory hogging, I decided to make this.
WorkerQueue can execute any task, handle large amounts of data, perform tasks on a separate machine and execute
tasks either in parallel or in sequence. Got Work?


-----------
Installation
-----------

Clone the WorkerQueue repostitory
  git clone git://github.com/barttenbrinke/worker_queue.git vendor/plugins/worker_queue

Switch to the 1_0_stable branch if you don't like living on the edge.
  cd vendor/plugins/worker_queue
  git branch 1_0_stable

-----------
Usage
-----------
Whenever you want to background a task, just do the following:
  work = WorkerQueue::WorkerQueueItem.new
  work.class_name     = 'Someclass'
  work.method_name    = 'some_method'
  work.argument_hash  = {:monkey => :tail}
  work.binary_data    = '1234567890'
  work.save!

This will be picked up by the worker when the following command is called:
  WorkerQueue.work
  
  Which in turn will call:
  Someclass.some_method({:monkey => :tail, :binary_data => '1234567890')
    
It is advised too set up a cronjob that runs the supplied rake task:
  rake worker_queue:work
  
Let this run as freqently as possible. WorkerQueue will have no problem if it is instantiated
multiple times.

Note that WorkerQueue will run only one task of a single class at the same time.
So if you want to queue and execute the items one after the other, make sure all items are set
to the same class.
This is also very usefull for things like xml files that need to be handled in the order in
which they were uploaded.

If you just want to execute items in the background, supply a unique classname for each item and
WorkerQueue will try its best to complete them as fast as possible.

After the WorkerQueue has executed a task successfully, it will clear the binary (if any) and move on
to the next item. WorkerQueue has no problem with multiple instances of it being run a the same time.

Use the following migration to get the show on the road:

ruby script/generate worker_queue_migration

-----------
Notes
-----------
* The specs only run in a rails project with the WorkerQueue, rspec and rspec_on_rails plugins installed.
  This needs fixing.

* If you want to store big files in the binary_data field, make sure you MYSQL config accepts
inserts that are big enough.

* The tasks that get executed expect a Class.method(args_hash, binary_blob) that returns true
  or false.