This repository has been archived by the owner on Dec 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathworker.js
50 lines (39 loc) · 1.5 KB
/
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
const { once } = require('lodash');
require('./lib/mongoose');
const pluginJobs = require('./plugins/publish-to-udata/jobs');
var q = require('./lib/kue').jobs;
var csw = require('./lib/tasks/harvest-csw');
var wfs = require('./lib/tasks/lookup-wfs');
var processRecord = require('./lib/tasks/process-record').exec;
var consolidateDataset = require('./lib/tasks/consolidate-dataset').exec;
var RemoteResourceCheck = require('./lib/tasks/check-remote-resource');
// To remove in the future
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
require('ssl-root-cas/latest').inject();
q.process('harvest-csw', 2, csw.harvest);
q.process('lookup-wfs', 5, wfs.lookup);
q.process('process-record', 5, processRecord);
q.process('dataset:consolidate', 5, consolidateDataset);
q.process('udata:synchronizeOne', 5, pluginJobs.synchronizeOne);
q.process('udata:synchronizeAll', 1, pluginJobs.synchronizeAll);
q.process('remote-resource:check', 5, function (kueJob, doneCallback) {
var job = new RemoteResourceCheck(kueJob.data);
job.exec().nodeify(doneCallback);
});
var gracefulShutdown = once(function () {
q.shutdown(5000, function (err) {
console.error('Job queue is shut down. ', err || '');
process.exit();
});
});
process.on('message', function (msg) {
if (msg === 'shutdown') {
gracefulShutdown();
}
});
process.on('SIGTERM', gracefulShutdown);
process.on('uncaughtException', function (err) {
console.error('Uncaught exception!!');
console.error(err);
gracefulShutdown();
});