2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-07-23 22:02:36 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-08-26 14:10:58 +00:00
|
|
|
import * as durations from '../util/durations';
|
2021-09-17 18:27:53 +00:00
|
|
|
import type { LoggerType } from '../types/Logging';
|
2021-08-12 18:15:55 +00:00
|
|
|
import { exponentialBackoffMaxAttempts } from '../util/exponentialBackoff';
|
2022-02-08 17:30:42 +00:00
|
|
|
import type { SyncType } from './helpers/syncHelpers';
|
2021-08-30 22:59:34 +00:00
|
|
|
import {
|
2022-02-08 17:30:42 +00:00
|
|
|
SyncTypeList,
|
2021-08-30 22:59:34 +00:00
|
|
|
parseRawSyncDataArray,
|
2022-02-08 17:30:42 +00:00
|
|
|
runSyncJob,
|
|
|
|
} from './helpers/syncHelpers';
|
2021-08-30 22:59:34 +00:00
|
|
|
import { strictAssert } from '../util/assert';
|
|
|
|
import { isRecord } from '../util/isRecord';
|
2021-07-23 22:02:36 +00:00
|
|
|
|
2023-10-28 00:14:35 +00:00
|
|
|
import type { JOB_STATUS } from './JobQueue';
|
2021-07-23 22:02:36 +00:00
|
|
|
import { JobQueue } from './JobQueue';
|
|
|
|
import { jobQueueDatabaseStore } from './JobQueueDatabaseStore';
|
|
|
|
|
2021-08-26 14:10:58 +00:00
|
|
|
const MAX_RETRY_TIME = durations.DAY;
|
2021-07-23 22:02:36 +00:00
|
|
|
|
2021-08-30 22:59:34 +00:00
|
|
|
export type ReadSyncJobData = {
|
|
|
|
readSyncs: Array<SyncType>;
|
|
|
|
};
|
2021-07-23 22:02:36 +00:00
|
|
|
|
|
|
|
export class ReadSyncJobQueue extends JobQueue<ReadSyncJobData> {
|
|
|
|
protected parseData(data: unknown): ReadSyncJobData {
|
2021-08-30 22:59:34 +00:00
|
|
|
strictAssert(isRecord(data), 'data is not an object');
|
|
|
|
return { readSyncs: parseRawSyncDataArray(data.readSyncs) };
|
2021-07-23 22:02:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected async run(
|
|
|
|
{ data, timestamp }: Readonly<{ data: ReadSyncJobData; timestamp: number }>,
|
2021-08-17 15:43:26 +00:00
|
|
|
{ attempt, log }: Readonly<{ attempt: number; log: LoggerType }>
|
2023-10-28 00:14:35 +00:00
|
|
|
): Promise<typeof JOB_STATUS.NEEDS_RETRY | undefined> {
|
2022-02-08 17:30:42 +00:00
|
|
|
await runSyncJob({
|
2021-08-12 18:15:55 +00:00
|
|
|
attempt,
|
2021-08-17 15:43:26 +00:00
|
|
|
log,
|
2021-08-12 18:15:55 +00:00
|
|
|
maxRetryTime: MAX_RETRY_TIME,
|
|
|
|
syncs: data.readSyncs,
|
|
|
|
timestamp,
|
2022-02-08 17:30:42 +00:00
|
|
|
type: SyncTypeList.Read,
|
2021-07-23 22:02:36 +00:00
|
|
|
});
|
2023-10-28 00:14:35 +00:00
|
|
|
|
|
|
|
return undefined;
|
2021-07-23 22:02:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const readSyncJobQueue = new ReadSyncJobQueue({
|
|
|
|
store: jobQueueDatabaseStore,
|
|
|
|
queueType: 'read sync',
|
|
|
|
maxAttempts: exponentialBackoffMaxAttempts(MAX_RETRY_TIME),
|
|
|
|
});
|