2021-07-23 22:02:36 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
/* eslint-disable class-methods-use-this */
|
|
|
|
|
|
|
|
import * as z from 'zod';
|
|
|
|
import * as moment from 'moment';
|
2021-08-12 18:15:55 +00:00
|
|
|
import { exponentialBackoffMaxAttempts } from '../util/exponentialBackoff';
|
|
|
|
import { runReadOrViewSyncJob } from './helpers/runReadOrViewSyncJob';
|
2021-07-23 22:02:36 +00:00
|
|
|
|
|
|
|
import { JobQueue } from './JobQueue';
|
|
|
|
import { jobQueueDatabaseStore } from './JobQueueDatabaseStore';
|
|
|
|
|
|
|
|
const MAX_RETRY_TIME = moment.duration(1, 'day').asMilliseconds();
|
|
|
|
|
|
|
|
const readSyncJobDataSchema = z.object({
|
|
|
|
readSyncs: z.array(
|
|
|
|
z.object({
|
|
|
|
messageId: z.string().optional(),
|
|
|
|
senderE164: z.string().optional(),
|
|
|
|
senderUuid: z.string().optional(),
|
|
|
|
timestamp: z.number(),
|
|
|
|
})
|
|
|
|
),
|
|
|
|
});
|
|
|
|
|
|
|
|
export type ReadSyncJobData = z.infer<typeof readSyncJobDataSchema>;
|
|
|
|
|
|
|
|
export class ReadSyncJobQueue extends JobQueue<ReadSyncJobData> {
|
|
|
|
protected parseData(data: unknown): ReadSyncJobData {
|
|
|
|
return readSyncJobDataSchema.parse(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async run(
|
|
|
|
{ data, timestamp }: Readonly<{ data: ReadSyncJobData; timestamp: number }>,
|
|
|
|
{ attempt }: Readonly<{ attempt: number }>
|
|
|
|
): Promise<void> {
|
2021-08-12 18:15:55 +00:00
|
|
|
await runReadOrViewSyncJob({
|
|
|
|
attempt,
|
|
|
|
isView: false,
|
|
|
|
maxRetryTime: MAX_RETRY_TIME,
|
|
|
|
syncs: data.readSyncs,
|
|
|
|
timestamp,
|
2021-07-23 22:02:36 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const readSyncJobQueue = new ReadSyncJobQueue({
|
|
|
|
store: jobQueueDatabaseStore,
|
|
|
|
|
|
|
|
queueType: 'read sync',
|
|
|
|
|
|
|
|
maxAttempts: exponentialBackoffMaxAttempts(MAX_RETRY_TIME),
|
|
|
|
});
|