2022-02-08 17:30:42 +00:00
|
|
|
// Copyright 2021-2022 Signal Messenger, LLC
|
2021-08-12 18:15:55 +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-08-12 18:15:55 +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-08-12 18:15:55 +00:00
|
|
|
|
2021-08-30 22:59:34 +00:00
|
|
|
export type ViewSyncJobData = {
|
|
|
|
viewSyncs: Array<SyncType>;
|
|
|
|
};
|
2021-08-12 18:15:55 +00:00
|
|
|
|
|
|
|
export class ViewSyncJobQueue extends JobQueue<ViewSyncJobData> {
|
|
|
|
protected parseData(data: unknown): ViewSyncJobData {
|
2021-08-30 22:59:34 +00:00
|
|
|
strictAssert(isRecord(data), 'data is not an object');
|
|
|
|
return { viewSyncs: parseRawSyncDataArray(data.viewSyncs) };
|
2021-08-12 18:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected async run(
|
|
|
|
{ data, timestamp }: Readonly<{ data: ViewSyncJobData; timestamp: number }>,
|
2021-08-17 15:43:26 +00:00
|
|
|
{ attempt, log }: Readonly<{ attempt: number; log: LoggerType }>
|
2021-08-12 18:15:55 +00:00
|
|
|
): Promise<void> {
|
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.viewSyncs,
|
|
|
|
timestamp,
|
2022-02-08 17:30:42 +00:00
|
|
|
type: SyncTypeList.View,
|
2021-08-12 18:15:55 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const viewSyncJobQueue = new ViewSyncJobQueue({
|
|
|
|
store: jobQueueDatabaseStore,
|
|
|
|
queueType: 'view sync',
|
|
|
|
maxAttempts: exponentialBackoffMaxAttempts(MAX_RETRY_TIME),
|
|
|
|
});
|