-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_worker.js
More file actions
52 lines (42 loc) · 1.23 KB
/
example_worker.js
File metadata and controls
52 lines (42 loc) · 1.23 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
49
50
51
52
/**
* NOTE: run `npm i sqs-worker` before doing this example
*/
var spark_jobserver = require('spark_jobserver'),
SQSWorker = require('sqs-worker');
var config = {
host: "localhost:8090",
queue: {
key: "<aws key>",
secret: "<aws secret>",
region: "us-east-1",
name: "/838405463324/jobs-queued"
}
};
var endpoint = 'https://sqs.' + config.queue.region + '.amazonaws.com';
var opts = {
endpoint: endpoint,
region: config.queue.region,
url: endpoint + config.queue.name
};
var queue_worker = new SQSWorker(opts, worker);
var jobserver = new spark_jobserver({host: config.host});
function worker(message, done) {
try {
message = JSON.parse(message);
console.log(message);
} catch (err) {
throw err;
}
jobserver.jobs.start(message.appName, message.classPath, message.options, message.body, function(err, data){
console.log(data);
var success = false;
success = (data.status == 'STARTED') || (data.status == 'ERROR') || (data.status == 'VALIDATION FAILED');
if ((data.status == 'ERROR') || (data.status == 'VALIDATION FAILED')) {
// let the humans know
}
if (data.status == 'NO SLOTS AVAILABLE') {
// sleep and try again later?
}
done(null, success);
});
}