-
Notifications
You must be signed in to change notification settings - Fork 40
/
simple-decider-worker.js
57 lines (44 loc) · 1.54 KB
/
simple-decider-worker.js
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
49
50
51
52
53
54
55
56
57
var swf = require('../index');
var myDecider = new swf.Decider({
"domain": "test-domain",
"taskList": {"name": "my-workflow-tasklist"},
"identity": "Decider-01",
"maximumPageSize": 100,
"reverseOrder": false // IMPORTANT: must replay events in the right order, ie. from the start
});
myDecider.on('decisionTask', function (decisionTask) {
console.log("Got a new decision task !");
if(!decisionTask.eventList.scheduled('step1')) {
decisionTask.response.schedule({
name: 'step1',
activity: 'simple-activity'
});
}
else {
decisionTask.response.stop({
result: "some workflow output data"
});
}
decisionTask.response.respondCompleted(decisionTask.response.decisions, function(err, result) {
if(err) {
console.log(err);
return;
}
console.log("responded with some data !");
});
});
myDecider.on('poll', function(d) {
//console.log(_this.config.identity + ": polling for decision tasks...");
console.log("polling for tasks...", d);
});
// Start polling
myDecider.start();
/**
* It is not recommanded to stop the poller in the middle of a long-polling request,
* because SWF might schedule an DecisionTask to this poller anyway, which will obviously timeout.
*
* The .stopHandler() method will wait for the end of the current polling request,
* eventually wait for a last decision execution, then stop properly :
*/
process.on('SIGINT', myDecider.stopHandler);
process.on('SIGTERM', myDecider.stopHandler);