Queued

Provides a high-level abstraction of Resque jobs that map cleanly to ActiveRecord (Rails) instances.

Normally, Resque jobs are seperate classes that model job specific functionality. This requires seperate tests, etc. Queued's approach is to just treat any instance method as a something that can be invoked as a job by Resque.

What It Does

Queued patches a smart proxy into your AR instances that allow you to acces the functionality by calling .queued or .qd. From there any instance method may be called and invoked asynchronously.

Caveats

  • A record must be saved and reachable by an id field.
  • Assumes a Rails application with Resque setup.
  • does not handle Singleton methods (yet).
  • defaults the queue name to the instance class name. the queued method accepts an override.
  • Be sensible when calling methods and passing large objects to them. These arguments must be marshalled as json to be enqueued by resque. It is a best practice (in Resque as well) to pass simple parameters.

Install

gem "queued", "0.0.1"

Usage

Basic Example:

record = Thing.find(42)
record.queued.do_long_running_operation(:times => 50)

To Target a Specific Resque Queue:

record = Thing.find(42)
record.queued(:archive).truncate!

Additionally, the .queued method is aliased to .qd for brevity.

Contributing

Fork it. Patches or pull requests are welcome.

License