resque-workflow: A DSL for describing workflows whose steps are Resque jobs
- Tony Arcieri
- 2010-10-22 @ 02:44
We use Resque to manage complex, multi-step workflows, and right now our
means of doing this is pretty ad hoc. We have idempotent jobs that can be
safely auto-retried in the case of failures (e.g. unresolved bugs or remote
service failures), and I'd like a DSL to describe our workflows and step
through them. To further complexify things, some of the steps of our jobs
require manual intervention, in which case our Rails app would need to
advance the state of the workflow after some form of user interaction.
I've been sort of hacking on a gem to do this for awhile, it's available
The state of the workflow is persisted in a database via ActiveRecord. I've
designed Resque::Workflow as a module you can include in an
So far all it does is build classes for Resque jobs based on the workflow
you describe. Trying to spec things out becomes a bit complex when Resque
itself and its asynchronous nature becomes involved... I might try mocking
out the interaction with Resque itself.
Anyway, if anyone else is interested in something like this, I just wanted
you all to know I'm taking a stab at it. Below is the workflow I've been
using in the spec:
class Cat < ActiveRecord::Base
states :new, :caught, :in_bathroom, :washed, :default => :new
# Catch the cat
job_for :new, :success => :caught do |cat|
puts "Catching the cat..."
# Walk to bathroom
job_for :caught, :success => :in_bathroom, :fail => :new do |cat|
puts "Carrying cat to the bathroom"
# Wash cat
job_for :in_bathroom, :success => :washed do |cat|
puts "Washing cat"
puts "Cat caught!"
puts "Cat carried to bathroom!"
puts "Cat washed!"
Medioh! A Kudelski Brand
Re: [resque] resque-workflow: A DSL for describing workflows whose steps are Resque jobs
- Thibaut Barrère
- 2010-10-22 @ 07:54
Thanks for sharing, I'll have a closer look.