Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
oxabz committed Jul 6, 2021
1 parent ace5557 commit a4d0065
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
25 changes: 12 additions & 13 deletions BackEnd/adapter/bullAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Queue extends event.EventEmitter {
}

/**
* Add jobs to the que
* Add jobs to the queue
* @param jobsData data for the process
* @param {String } name of the processor
* @param {number} poolSize? number by which the jobs will be grouped
Expand Down Expand Up @@ -195,24 +195,27 @@ class Queue extends event.EventEmitter {
}
});

let isRetry = job.data.errors.filter(x => x === null || x === undefined).length !== subJobs.length;
let failed = false;
let i = 0
for (let j of subJobs) {
await new Promise((resolve, reject) => {
if (!isRetry || !job.data.errors[i]) await new Promise((resolve, reject) => {
try {
processor(j, (err, res) => {
job.data.errors[i] = err;
job.data.results[i] = res;
job.update(job.data).then(() => resolve());
});
} catch (e) {
failed = true;
job.data.errors[i] = e;
job.update(job.data).then(() => resolve());
}
})
i++;
}

done(null, true);
done(failed ? job.data.errors : null, true);
}
}

Expand Down Expand Up @@ -277,16 +280,12 @@ class BatchedJob extends Job {

getState() {
return super.getState().then(state => {
if (state === Queue.JOB_STATES.ACTIVE) {
if (this._bullJob.data.results[this._i] !== null && this._bullJob.data.results[this._i] !== undefined) return Queue.JOB_STATES.COMPLETED;
if (this._bullJob.data.errors[this._i] !== null && this._bullJob.data.errors[this._i] !== undefined) return Queue.JOB_STATES.FAILED;
if (this._i === 0 ||
this._bullJob.data.results[this._i - 1] !== null && this._bullJob.data.results[this._i - 1] !== undefined ||
this._bullJob.data.errors[this._i - 1] !== null && this._bullJob.data.errors[this._i - 1] !== undefined) return Queue.JOB_STATES.ACTIVE;
return Queue.JOB_STATES.WAITING;
} else {
return state;
}
if (this._bullJob.data.results[this._i] !== null && this._bullJob.data.results[this._i] !== undefined) return Queue.JOB_STATES.COMPLETED;
if (this._bullJob.data.errors[this._i] !== null && this._bullJob.data.errors[this._i] !== undefined) return Queue.JOB_STATES.FAILED;
if (this._i === 0 ||
this._bullJob.data.results[this._i - 1] !== null && this._bullJob.data.results[this._i - 1] !== undefined ||
this._bullJob.data.errors[this._i - 1] !== null && this._bullJob.data.errors[this._i - 1] !== undefined) return Queue.JOB_STATES.ACTIVE;
return Queue.JOB_STATES.WAITING;
});
}

Expand Down
19 changes: 17 additions & 2 deletions BackEnd/model/tasks/RetrieveTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,25 @@ class RetrieveTask {
* @returns {Task} the task info
*/
static async getTask(id) {
const sorter = (a, b) => {
if (a.data.AnswerId === b.data.AnswerId) {
if (a.data.AnswerNumber === b.data.AnswerNumber) {
return 0;
} else if (a.data.AnswerNumber > b.data.AnswerNumber) {
return 1;
} else {
return -1;
}
} else if (a.data.AnswerId > b.data.AnswerId) {
return 1;
} else {
return -1;
}
};
//Gathering the jobs of the corresponding task
let validationJobs = await RetrieveTask._getValidationJobs(id);
let validationJobs = (await RetrieveTask._getValidationJobs(id)).sort(sorter);
if (validationJobs.length === 0) return null; //If no jobs of this task exist then the task doesn't exist
let retrieveJobs = await RetrieveTask._getRetrieveJobs(id);
let retrieveJobs = (await RetrieveTask._getRetrieveJobs(id)).sort(sorter);
let progress = await RetrieveTask.getProgress(validationJobs, retrieveJobs);

//Making state
Expand Down

0 comments on commit a4d0065

Please sign in to comment.