Initial support for job queue

This commit is contained in:
Evan Hahn 2021-04-29 18:02:27 -05:00 committed by GitHub
parent 1238cca538
commit bbd7fd3854
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 1708 additions and 28 deletions

22
ts/jobs/JobError.ts Normal file
View file

@ -0,0 +1,22 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { reallyJsonStringify } from '../util/reallyJsonStringify';
/**
* An error that wraps job errors.
*
* Should not be instantiated directly, except by `JobQueue`.
*/
export class JobError extends Error {
constructor(public readonly lastErrorThrownByJob: unknown) {
super(`Job failed. Last error: ${formatError(lastErrorThrownByJob)}`);
}
}
function formatError(err: unknown): string {
if (err instanceof Error) {
return err.message;
}
return reallyJsonStringify(err);
}