2021-08-17 15:43:26 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { z } from 'zod';
|
2021-09-17 18:27:53 +00:00
|
|
|
import type { LoggerType } from '../types/Logging';
|
2021-08-17 15:43:26 +00:00
|
|
|
import { exponentialBackoffMaxAttempts } from '../util/exponentialBackoff';
|
2021-12-07 22:41:40 +00:00
|
|
|
import { receiptSchema, ReceiptType } from '../types/Receipt';
|
|
|
|
import { MAX_RETRY_TIME, runReceiptJob } from './helpers/receiptHelpers';
|
2021-08-17 15:43:26 +00:00
|
|
|
|
|
|
|
import { JobQueue } from './JobQueue';
|
|
|
|
import { jobQueueDatabaseStore } from './JobQueueDatabaseStore';
|
|
|
|
|
2021-12-07 22:41:40 +00:00
|
|
|
const viewedReceiptsJobDataSchema = z.object({ viewedReceipt: receiptSchema });
|
2021-08-17 15:43:26 +00:00
|
|
|
|
|
|
|
type ViewedReceiptsJobData = z.infer<typeof viewedReceiptsJobDataSchema>;
|
|
|
|
|
|
|
|
export class ViewedReceiptsJobQueue extends JobQueue<ViewedReceiptsJobData> {
|
|
|
|
protected parseData(data: unknown): ViewedReceiptsJobData {
|
|
|
|
return viewedReceiptsJobDataSchema.parse(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async run(
|
|
|
|
{
|
|
|
|
data,
|
|
|
|
timestamp,
|
|
|
|
}: Readonly<{ data: ViewedReceiptsJobData; timestamp: number }>,
|
|
|
|
{ attempt, log }: Readonly<{ attempt: number; log: LoggerType }>
|
|
|
|
): Promise<void> {
|
2021-12-07 22:41:40 +00:00
|
|
|
await runReceiptJob({
|
2021-08-17 15:43:26 +00:00
|
|
|
attempt,
|
|
|
|
log,
|
2021-12-07 22:41:40 +00:00
|
|
|
timestamp,
|
|
|
|
receipts: [data.viewedReceipt],
|
|
|
|
type: ReceiptType.Viewed,
|
2021-08-17 15:43:26 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const viewedReceiptsJobQueue = new ViewedReceiptsJobQueue({
|
|
|
|
store: jobQueueDatabaseStore,
|
|
|
|
queueType: 'viewed receipts',
|
|
|
|
maxAttempts: exponentialBackoffMaxAttempts(MAX_RETRY_TIME),
|
|
|
|
});
|