-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpriorityworker.js
More file actions
48 lines (42 loc) · 1.29 KB
/
priorityworker.js
File metadata and controls
48 lines (42 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* Created by mox on 21/03/16.
*
* Fatus worker with priority (on other workers)
*
*/
'use strict';
const MODULE_NAME = 'FatusPriorityWorker';
const FatusWorker = require('./worker');
const moment = require('moment');
/** the worker for the fatus */
class FatusPriorityWorker extends FatusWorker {
/**
* get a new job from the queue NOT FAILED
* @param th
* @param wfcallback
* @override
*/
fetchNewJob(th, wfcallback) {
let NOW = moment();
th.fetchIteration = th.fetchIteration +1;
if(th.fetchIteration<(th.STACK_PROTECTION_THRSD*2)) {
th.fatus.getQueueTop(function onGet(err, msg) {
if (!err && msg && msg[0] && msg[0].messageText) {
let reservedCondition = th.isMsgReserved(msg,NOW,th);
let notfailedCondition = msg[0].messageText.fail;
if (reservedCondition || notfailedCondition){
return th.fetchNewJob(th, wfcallback);
}else{
wfcallback(err, msg);
}
}else{
wfcallback(err, null);
}
});
}else{
wfcallback(null,null);
}
}
}
/** Exports */
module.exports = FatusPriorityWorker;