Retry outbound "normal" messages for up to a day

This commit is contained in:
Evan Hahn 2021-08-31 15:58:39 -05:00 committed by GitHub
parent 62cf51c060
commit a85dd1be36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 1414 additions and 603 deletions

View file

@ -136,12 +136,23 @@ export abstract class JobQueue<T> {
* If `streamJobs` has not been called yet, this will throw an error.
*/
async add(data: Readonly<T>): Promise<Job<T>> {
this.throwIfNotStarted();
const job = this.createJob(data);
await this.store.insert(job);
log.info(`${this.logPrefix} added new job ${job.id}`);
return job;
}
protected throwIfNotStarted(): void {
if (!this.started) {
throw new Error(
`${this.logPrefix} has not started streaming. Make sure to call streamJobs().`
);
}
}
protected createJob(data: Readonly<T>): Job<T> {
const id = uuid();
const timestamp = Date.now();
@ -158,11 +169,7 @@ export abstract class JobQueue<T> {
}
})();
log.info(`${this.logPrefix} added new job ${id}`);
const job = new Job(id, timestamp, this.queueType, data, completion);
await this.store.insert(job);
return job;
return new Job(id, timestamp, this.queueType, data, completion);
}
private async enqueueStoredJob(storedJob: Readonly<StoredJob>) {