librelist archives

« back to archive

Unique jobs plugin

Unique jobs plugin

From:
Jannis Hermanns
Date:
2010-08-03 @ 13:22
Hey,

I needed support for unique jobs in resque. Unique as in "Identical
jobs should only exist once per queue".

----------8<------------
class CacheSweeper < Resque::Plugins::Loner::UniqueJob
   ...
end

>> Resque.enqueue CacheSweeper, 1
=> "OK"
>> Resque.enqueue CacheSweeper, 1
=> "EXISTED"
>> Resque.size :cache_sweeps
=> 1

---------->8------------

When you try to enqueue a job that is already enqueued, with the same
parameters, then the enqueue method returns "EXISTED" instead of "OK"
and does not enqueue the job again.

You can have a look at it here: <http://github.com/jayniz/resque-loner

It does not only use hooks, unfortunately, see the end of the README.
If you have an idea how to turn this into a pure plugin, let me know
:)


Cheers,
Jannis.
--
✉ jannis hermanns · salzachstr 6 · 14163 berlin · germany     » http://jann.is
_______________________________________________________________________________
Never argue with idiots.
They drag you down to their level and beat you with experience.

Re: [resque] Unique jobs plugin

From:
Chris Wanstrath
Date:
2010-08-03 @ 22:41
On Tue, Aug 3, 2010 at 6:22 AM, Jannis Hermanns <jannis@gmail.com> wrote:

> It does not only use hooks, unfortunately, see the end of the README.
> If you have an idea how to turn this into a pure plugin, let me know
> :)

What if we add a `before_enqueue` hook?

Re: [resque] Unique jobs plugin

From:
Jannis Hermanns
Date:
2010-08-04 @ 08:12
On Wed, Aug 4, 2010 at 12:41 AM, Chris Wanstrath <chris@ozmm.org> wrote:
> What if we add a `before_enqueue` hook?

Yeah, this hook would be needed as well as an `after_destroy` hook so
the "queued" flag for a job can be removed upon destruction.

That would be quite cool!


Cheers,
Jannis.
-- 
✉ jannis hermanns · salzachstr 6 · 14163 berlin · germany     » http://jann.is
_______________________________________________________________________________
Never argue with idiots.
They drag you down to their level and beat you with experience.

Re: [resque] Unique jobs plugin

From:
Lee Marlow
Date:
2010-08-03 @ 22:44
That sounds like a good idea to me.  It would make this plugin simpler
as well as some others, my resque-meta plugin for one.

On Tue, Aug 3, 2010 at 4:41 PM, Chris Wanstrath <chris@ozmm.org> wrote:
> On Tue, Aug 3, 2010 at 6:22 AM, Jannis Hermanns <jannis@gmail.com> wrote:
>
>> It does not only use hooks, unfortunately, see the end of the README.
>> If you have an idea how to turn this into a pure plugin, let me know
>> :)
>
> What if we add a `before_enqueue` hook?
>