gresrun / jesque

An implementation of Resque in Java.
http://gresrun.github.io/jesque
Apache License 2.0
630 stars 131 forks source link

Removing an enqueued job by key #87

Closed seglo closed 9 years ago

seglo commented 9 years ago

Hey,

I have a use case for the delay queue implementation of jesque. Delaying works great, but I also want the option to remove things from the queue. The call to removeDelayedEnqueue requires the queue name and the Job that includes the whole payload I originally queued. I would like to be able to remove something from the queue based on a key instead of the whole payload.

Am I missing something here? When I look at the implementation it looks like the whole value is serialized as the key & value when calling zadd.

seglo commented 9 years ago

To elaborate. Say I have a record of data I want to delay processing on.

class FooRecord
- id
- otherData

I want to call delayedEnqueue with the entire payload, but use the id as the key exclusively. When items are dequeued I want to get the entire payload.

If for some reason I need to remove a record from the queue I want to remove it by its id, because I may not know the other fields at the time (description). The signature for removeDelayedEnqueue requires the whole payload because everything is used for generating the key in redis.

Please advise.

seglo commented 9 years ago

When I dug deeper into the Jesque impl. and actual Redis commands I discovered that the Jesque behaviour is consistent. I worked around this by using Jedis directly. I add the key to a sorted set using time as score (just like Jesque), but in the same transaction I add a normal key/value pair to redis. On the consumer side I get all new messages from the sorted set, and then get/delete the value from redis.