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

View file

@ -0,0 +1,35 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as z from 'zod';
import { JobQueue } from './JobQueue';
import { jobQueueDatabaseStore } from './JobQueueDatabaseStore';
const removeStorageKeyJobDataSchema = z.object({
key: z.string().min(1),
});
type RemoveStorageKeyJobData = z.infer<typeof removeStorageKeyJobDataSchema>;
export const removeStorageKeyJobQueue = new JobQueue<RemoveStorageKeyJobData>({
store: jobQueueDatabaseStore,
queueType: 'remove storage key',
maxAttempts: 100,
parseData(data: unknown): RemoveStorageKeyJobData {
return removeStorageKeyJobDataSchema.parse(data);
},
async run({
data,
}: Readonly<{ data: RemoveStorageKeyJobData }>): Promise<void> {
await new Promise<void>(resolve => {
window.storage.onready(resolve);
});
await window.storage.remove(data.key);
},
});