Job Already Delayed Check
- Dominant language
- JavaScript
- Stars
- 9.4k
- Forks
- 858
- PR merge metrics
- No merged PRs in 30d
Description
Hey guys!
I have to start some recurrent jobs at the server start-up. To make sure a job doesn't delay twice I had to come up with some kind of a checkAlreadyDelayed function. It would be great to add a native kue check function or, even better, add a possibility to tell kue to make the job unique ( smth like kue.create('myjob').delay(1000).unique().save() ).
I could come up with a pull request at no time, just let me know if you find this case relevant.
So far I've been using this:
```
module.exports.checkJobAlreadyDelayed = function *(name) {
logger.debug('jobHelper.checkJobAlreadyDelayed -> init');
var ids = yield redis.zrangeAsync(kuePrefix + ':jobs:delayed', 0, -1);
var keys;
keys = _.map(ids, function (id) {
return kuePrefix + ':job:' + id.substr(id.indexOf('|')+1);
});
keys = yield _.map(keys, function (key) {
return redis.hgetAsync(key, 'type');
});
var resDelayed = _.reduce(keys, function (total, val) {
return total || (val === name);
}, false);
ids = yield redis.zrangeAsync(kuePrefix + ':jobs:inactive', 0, -1);
keys = _.map(ids, function (id) {
return kuePrefix + ':job:' + id.substr(id.indexOf('|')+1);
});
keys = yield _.map(keys, function (key) {
return redis.hgetAsync(key, 'type');
});
var resInactive = _.reduce(keys, function (total, val) {
return total || (val === name);
}, false);
return resDelayed || resInactive;
};
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing Kue's job creation and delay flow, then inspect the Redis delayed and inactive job sets shown in the issue. Define how the requested duplicate check or unique-job behavior should work across those states; done means the chosen API reliably prevents or detects a job being delayed twice.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, redis
- Domain
- backend, distributed-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100