Skip to content

Probably do not need internal resolve/reject map #18

Closed
@thebongy

Description

@thebongy

I was browsing through the bulljs reference docs, and found that every job has job.finished() which returns a promise that resolves when the job has finished
https://github.com/OptimalBits/bull/blob/develop/REFERENCE.md#jobfinished

So technically, we do not need the internal map logic in code-executor which maintains maps from job IDs to promises, as bulljs already does this internally.

this.jobs = new Map();
this.queue.on('global:completed', (_job: Bull.Job, result: string) => {
const { id } = <Result>JSON.parse(result);
logger.debug(`Running on complete for id: ${id}`);
const currentJob = this.jobs.get(id);
if (currentJob) {
currentJob.resolve(result);
this.jobs.delete(id);
}
});
}
async runCode(codeOptions: CodeParams): Promise<void> {
const id = uuid();
const codeObject = { ...codeOptions, id };
logger.info(`Running code with id: ${id}`);
return new Promise((resolve, reject) => {
this.jobs.set(id, { resolve, reject });
this.queue.add(codeObject);
});
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions