This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuploaderworker.js
56 lines (47 loc) · 1.58 KB
/
uploaderworker.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
const rfqQueue = require('rethinkdb-job-queue');
const extend = require('util')._extend;
const config = require('config');
let rethink = require('rethinkdb');
let connctionOption = extend({}, config.get('rethinkDBConnection'));
if (process.env.rdbHost !== undefined && process.env.rdbHost !== '') {
connctionOption.host = process.env.rdbHost;
}
if (process.env.rdbPort !== undefined && process.env.rdbPort !== '') {
connctionOption.port = process.env.rdbPort;
}
const doJob = require('./uploader.js');
const doJobInventory = require('./uploaderInventory.js');
let queueOption = {
name: 'uploaderJobQue'
};
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection reason:', reason, p);
// application specific logging, throwing an error, or other logic here
});
const objQ = new rfqQueue(connctionOption, queueOption);
objQ.on('error', (err) => {
console.log('Queue Id: ' + err.queueId);
console.error(err);
});
function getJobQueue () {
objQ.process(async (job, next) => {
try {
// Send email using job.recipient as the destination address
console.log('======startImportToPDM======');
// console.log(job)
if (job.data.uploadType == 'inventory') {
await doJobInventory(job, next).catch((err) => {
console.log('===========doJob=err======', err);
})
} else {
await doJob(job, next).catch((err) => {
console.log('===========doJob=err======', err);
})
}
console.log('======startImportToPDM=end=====');
} catch (err) {
return next(err);
}
})
}
getJobQueue()