Track dateCreated, fixes

pull/95/head
Piero Toffanin 2019-10-01 23:43:49 -04:00
rodzic ced6a83cba
commit fd677e8048
3 zmienionych plików z 17 dodań i 2 usunięć

Wyświetl plik

@ -44,6 +44,7 @@ module.exports = class Task{
this.uuid = uuid;
this.name = name !== "" ? name : "Task of " + (new Date()).toISOString();
this.dateCreated = isNaN(parseInt(dateCreated)) ? new Date().getTime() : parseInt(dateCreated);
this.dateStarted = 0;
this.processingTime = -1;
this.setStatus(statusCodes.QUEUED);
this.options = options;
@ -207,6 +208,10 @@ module.exports = class Task{
return this.status.code === statusCodes.CANCELED;
}
isRunning(){
return this.status.code === statusCodes.RUNNING;
}
// Cancels the current task (unless it's already canceled)
cancel(cb){
if (this.status.code !== statusCodes.CANCELED){
@ -418,6 +423,7 @@ module.exports = class Task{
if (this.status.code === statusCodes.QUEUED){
this.startTrackingProcessingTime();
this.dateStarted = new Date().getTime();
this.setStatus(statusCodes.RUNNING);
let runnerOptions = this.options.reduce((result, opt) => {
@ -471,6 +477,7 @@ module.exports = class Task{
if ([statusCodes.CANCELED, statusCodes.FAILED, statusCodes.COMPLETED].indexOf(this.status.code) !== -1){
this.setStatus(statusCodes.QUEUED);
this.dateCreated = new Date().getTime();
this.dateStarted = 0;
this.output = [];
this.progress = 0;
this.stopTrackingProcessingTime(true);
@ -565,6 +572,7 @@ module.exports = class Task{
uuid: this.uuid,
name: this.name,
dateCreated: this.dateCreated,
dateStarted: this.dateStarted,
status: this.status,
options: this.options,
webhook: this.webhook,

Wyświetl plik

@ -316,10 +316,12 @@ class TaskManager{
checkTimeouts(){
if (config.maxRuntime > 0){
let now = new Date().getTime();
for (let uuid in this.tasks){
let task = this.tasks[uuid];
if (!task.isCanceled() && task.processingTime > config.maxRuntime * 60 * 1000){
if (task.isRunning() && task.dateStarted > 0 && (now - task.dateStarted) > config.maxRuntime * 60 * 1000){
task.output.push(`Task timed out after ${Math.ceil(task.processingTime / 60 / 1000)} minutes.\n`);
this.cancel(uuid, () => {
logger.warn(`Task ${uuid} timed out`);

Wyświetl plik

@ -295,7 +295,12 @@ module.exports = {
},
// Remove
fs.unlink(seedFileDst, cb)
cb => {
fs.exists(seedFileDst, exists => {
if (exists) fs.unlink(seedFileDst, cb);
else cb();
});
}
], cb);
}