-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathsimple-activity-worker.js
47 lines (35 loc) · 1.26 KB
/
simple-activity-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
/**
* This simple worker example will respond to any incoming task
* on the 'my-workflow-tasklist, by setting the input parameters as the results of the task
*/
var swf = require('../index');
var activityPoller = new swf.ActivityPoller({
domain: 'test-domain',
taskList: { name: 'my-workflow-tasklist' },
identity: 'simple poller ' + process.pid
});
activityPoller.on('activityTask', function(task) {
console.log("Received new activity task !");
var output = task.config.input;
task.respondCompleted(output, function (err) {
if(err) {
console.log(err);
return;
}
console.log("responded with some data !");
});
});
activityPoller.on('poll', function(d) {
console.log("polling for activity tasks...", d);
});
// Start polling
activityPoller.start();
/**
* It is not recommanded to stop the poller in the middle of a long-polling request,
* because SWF might schedule an ActivityTask 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 activity execution, then stop properly :
*/
process.on('SIGINT', activityPoller.stopHandler);
process.on('SIGTERM', activityPoller.stopHandler);