2018-07-22 08:40:15 -07:00
|
|
|
const { AssetGuard } = require('./assetguard')
|
2018-01-18 20:45:50 -08:00
|
|
|
|
2018-07-22 08:40:15 -07:00
|
|
|
const tracker = new AssetGuard(process.argv[2], process.argv[3])
|
2018-01-18 20:45:50 -08:00
|
|
|
console.log('AssetExec Started')
|
|
|
|
|
|
|
|
// Temporary for debug purposes.
|
|
|
|
process.on('unhandledRejection', r => console.log(r))
|
|
|
|
|
2018-07-22 08:40:15 -07:00
|
|
|
tracker.on('validate', (data) => {
|
|
|
|
process.send({context: 'validate', data})
|
2018-04-07 15:06:49 -07:00
|
|
|
})
|
2018-07-22 08:40:15 -07:00
|
|
|
tracker.on('progress', (data, acc, total) => {
|
|
|
|
process.send({context: 'progress', data, value: acc, total, percent: parseInt((acc/total)*100)})
|
2018-04-28 17:52:13 -07:00
|
|
|
})
|
2018-07-22 08:40:15 -07:00
|
|
|
tracker.on('complete', (data, ...args) => {
|
|
|
|
process.send({context: 'complete', data, args})
|
2018-01-18 20:45:50 -08:00
|
|
|
})
|
2018-07-22 08:40:15 -07:00
|
|
|
tracker.on('error', (data, error) => {
|
|
|
|
process.send({context: 'error', data, error})
|
2018-05-06 18:45:20 -07:00
|
|
|
})
|
|
|
|
|
2018-01-18 20:45:50 -08:00
|
|
|
process.on('message', (msg) => {
|
2018-07-22 08:40:15 -07:00
|
|
|
if(msg.task === 'execute'){
|
|
|
|
const func = msg.function
|
2018-04-02 15:40:32 -07:00
|
|
|
let nS = tracker[func]
|
|
|
|
let iS = AssetGuard[func]
|
|
|
|
if(typeof nS === 'function' || typeof iS === 'function'){
|
|
|
|
const f = typeof nS === 'function' ? nS : iS
|
|
|
|
const res = f.apply(f === nS ? tracker : null, msg.argsArr)
|
2018-01-18 20:45:50 -08:00
|
|
|
if(res instanceof Promise){
|
|
|
|
res.then((v) => {
|
2018-07-22 08:40:15 -07:00
|
|
|
process.send({result: v, context: func})
|
2018-05-08 03:34:16 -07:00
|
|
|
}).catch((err) => {
|
2018-07-22 08:40:15 -07:00
|
|
|
process.send({result: err, context: func})
|
2018-01-18 20:45:50 -08:00
|
|
|
})
|
|
|
|
} else {
|
2018-07-22 08:40:15 -07:00
|
|
|
process.send({result: res, context: func})
|
2018-01-18 20:45:50 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
process.on('disconnect', () => {
|
|
|
|
console.log('AssetExec Disconnected')
|
|
|
|
process.exit(0)
|
|
|
|
})
|