Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async handleAction(message) {
let { payload, exchange, routes } = message;
// We encode the task id/run into the job guid so extract the task id.
let [taskId, runId] = payload.job_guid.split('/')
taskId = slugid.encode(taskId);
console.log(`Received ${payload.action} event for task ${taskId} by ${payload.requester}`);
let task = await this.queue.task(taskId);
switch (payload.action) {
case 'cancel':
await this.handleCancel(taskId, runId, task, payload);
break;
case 'retrigger':
await this.handleRetrigger(taskId, runId, task, payload);
break;
default:
console.log(`[action handler] unknown action ${payload.action}`);
}
}
}
return rows.reduce(function(tasks, row) {
// extract the task by task id (only create one)
var taskId = slugid.encode(row.taskId);
var task = byTaskId[taskId];
if (!task) {
task = byTaskId[taskId] = mapTask(taskId, row);
tasks.push(task);
}
if (row.runId) {
task.runs.push(mapRun(row));
}
return tasks;
}, []);
}
.then(function(rows) {
// Return 204, if no rows are available
if (rows.length === 0) {
return {
code: 204,
message: "No runs pending for given provisionerId and workerType"
};
}
var row = rows[0];
// Claim the run and be done with it
return that.claimTaskRun(
slugid.encode(row.taskId),
row.runId,
options,
knex
);
});
});
}
if (type == 'json') {
return JSON.parse(value);
}
if (type == 'date') {
assert(
value instanceof Date,
"Value '" + value + "' must be an instance of Date object for " +
"key " + entry.key
);
return value;
}
if (type == 'slugid') {
assert(typeof(value) == 'string', "Slugids should be returned from " +
"azure as strings");
return slugid.encode(value);
}
debug("Entry with unknown type: ", entry);
throw new Error("Can't deserialize unknown type: '" + type + "' for " +
"key: '" + entry.key + "'!");
};
.then(function(count) {
if (count === 0) {
debug("Failed to delete task %s in moveTaskFromDatabase",
slugid.encode(task.taskId));
}
});
});
this.runs.forEach(function(run) {
run.taskId = slugid.encode(run.taskId);
});
};
SlugIdType.prototype.deserialize = function(source) {
return slugid.encode(source[this.property]);
};
var Task = function(rowInfo) {
_.assign(this, rowInfo.taskRow);
this.taskId = slugid.encode(this.taskId);
this.taskGroupId = slugid.encode(this.taskGroupId);
this.routes = JSON.parse(this.routes);
this.runs = _.sortBy(rowInfo.runRows, 'runId');
this.runs.forEach(function(run) {
run.taskId = slugid.encode(run.taskId);
});
};
deserialize: function(r) {
assert.equal(typeof(r), 'string', "Slugids should be returned from " +
"azure as strings");
return slugid.encode(r);
}
});