2022-02-08 17:30:42 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import * as durations from '../util/durations';
|
|
|
|
import type { LoggerType } from '../types/Logging';
|
|
|
|
import { exponentialBackoffMaxAttempts } from '../util/exponentialBackoff';
|
|
|
|
import type { SyncType } from './helpers/syncHelpers';
|
|
|
|
import {
|
|
|
|
SyncTypeList,
|
|
|
|
parseRawSyncDataArray,
|
|
|
|
runSyncJob,
|
|
|
|
} from './helpers/syncHelpers';
|
|
|
|
import { strictAssert } from '../util/assert';
|
|
|
|
import { isRecord } from '../util/isRecord';
|
|
|
|
|
2023-10-28 00:14:35 +00:00
|
|
|
import type { JOB_STATUS } from './JobQueue';
|
2022-02-08 17:30:42 +00:00
|
|
|
import { JobQueue } from './JobQueue';
|
|
|
|
import { jobQueueDatabaseStore } from './JobQueueDatabaseStore';
|
|
|
|
|
|
|
|
const MAX_RETRY_TIME = durations.DAY;
|
|
|
|
|
|
|
|
export type ViewOnceOpenJobData = {
|
|
|
|
viewOnceOpens: Array<SyncType>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export class ViewOnceOpenJobQueue extends JobQueue<ViewOnceOpenJobData> {
|
|
|
|
protected parseData(data: unknown): ViewOnceOpenJobData {
|
|
|
|
strictAssert(isRecord(data), 'data is not an object');
|
|
|
|
return { viewOnceOpens: parseRawSyncDataArray(data.viewOnceOpens) };
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async run(
|
|
|
|
{
|
|
|
|
data,
|
|
|
|
timestamp,
|
|
|
|
}: Readonly<{ data: ViewOnceOpenJobData; timestamp: number }>,
|
|
|
|
{ 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({
|
|
|
|
attempt,
|
|
|
|
log,
|
|
|
|
maxRetryTime: MAX_RETRY_TIME,
|
|
|
|
syncs: data.viewOnceOpens,
|
|
|
|
timestamp,
|
|
|
|
type: SyncTypeList.ViewOnceOpen,
|
|
|
|
});
|
2023-10-28 00:14:35 +00:00
|
|
|
|
|
|
|
return undefined;
|
2022-02-08 17:30:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const viewOnceOpenJobQueue = new ViewOnceOpenJobQueue({
|
|
|
|
store: jobQueueDatabaseStore,
|
|
|
|
queueType: 'view once open sync',
|
|
|
|
maxAttempts: exponentialBackoffMaxAttempts(MAX_RETRY_TIME),
|
|
|
|
});
|