37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
const tf = require('./docker/tf');
|
|
const db = require('../mongo');
|
|
const path = require('path');
|
|
|
|
module.exports = async function(job){
|
|
|
|
var destroyMongo = await db.destroy.update(job.data.id, {
|
|
"status": "destroying",
|
|
"jobId": job.id,
|
|
"logFile": path.join('/logs', 'destroy', `${job.data.id}.log`)
|
|
});
|
|
|
|
var provMongo = await db.provision.getSingle(job.data.provId);
|
|
|
|
return tf.destroy(destroyMongo, provMongo)
|
|
.then(async function(output) {
|
|
let update, update2;
|
|
if ( output.indexOf("Error") !== -1 ) {
|
|
update = await db.destroy.update(destroyMongo._id,{"status": "error"});
|
|
update2 = await db.provision.update(destroyMongo.provId, {"isDestroyed": false});
|
|
} else {
|
|
update = await db.destroy.update(destroyMongo._id, {"status": "destroyed"});
|
|
update2 = await db.provision.update(destroyMongo.provId, {"isDestroyed": true});
|
|
}
|
|
return { destroy: update, provision: update2 };
|
|
}).then(async function(res) {
|
|
return Promise.resolve({"success": true, job: res});
|
|
}).catch(function(err) {
|
|
console.log("Processor Destroy: err", err);
|
|
db.destroy.update(destroyMongo._id, {"status": "error", "isDestroyed": false});
|
|
return Promise.reject({"success": false, "err": err});
|
|
});
|
|
|
|
}
|
|
|
|
|