bvandenbos/resque-scheduler — Issue #138: Plugin support
Author: andreas
Created: 2012-03-05 13:17:08+00:00
State: open

First of all, thanks for resque-scheduler! We use it with great pleasure for our startup.

I would like to propose a plugin architecture for resque-scheduler, similar to the plugin architecture of resque. Supporting plugins would allow keeping resque-scheduler lean, but still cater for shareable extensions. An example of such an extension is ensuring uniqueness of jobs, delayed or not, such as requested in multiple issues and pull requests (#41, #52, #113). This can't be written as a regular resque plugin.

Specifically, I suggest the following hooks:

* `before_delayed_enqueue`: Called with the timestamp and job args before a job is placed on the delayed queue. If the hook returns false, the job will not be placed on the delayed queue.
* `after_delayed_enqueue`: Called with the timestamp and job args after a job is placed on the queue. Any exception raised propagates up to the code which queued the job.
* `before_delayed_dequeue`: Called with the timestamp and job args before a job is removed from the delayed queue (e.g. [before this line](https://github.com/bvandenbos/resque-scheduler/blob/v1.9.9/lib/resque/scheduler.rb#L105)). If the hook returns false, the job will not be removed from the queue.
* `after_delayed_dequeue`: Called with the timestamp and job args after a job was removed from the delayed queue and the job was created (e.g. [after this line](https://github.com/bvandenbos/resque-scheduler/blob/v1.9.9/lib/resque/scheduler.rb#L114)).
* Maybe an `on_delayed_failure` ([corresponding to this line](https://github.com/bvandenbos/resque-scheduler/blob/v1.9.9/lib/resque/scheduler.rb#L117)).

The implementation ought to be quite simple, similar to resque (primarily [`Resque#enqueue_to`](https://github.com/defunkt/resque/blob/master/lib/resque.rb#L231) and [`Resque::Plugin`](https://github.com/defunkt/resque/blob/master/lib/resque/plugin.rb)). I volunteer trying my hand at writing the necessary changes if you are interested.