You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-desktop/ts/session/utils/job_runners/jobs/ConfigurationSyncJob.ts

46 lines
1.2 KiB
TypeScript

import { isNumber } from 'lodash';
import { v4 } from 'uuid';
import { sleepFor } from '../../Promise';
import { Persistedjob, SerializedPersistedJob } from '../PersistedJob';
export class ConfigurationSyncJob extends Persistedjob {
constructor({
identifier,
nextAttemptTimestamp,
maxAttempts,
currentRetry,
}: {
identifier: string | null;
nextAttemptTimestamp: number | null;
maxAttempts: number | null;
currentRetry: number;
}) {
super({
jobType: 'ConfigurationSyncJobType',
identifier: identifier || v4(),
delayBetweenRetries: 3000,
maxAttempts: isNumber(maxAttempts) ? maxAttempts : 3,
nextAttemptTimestamp: nextAttemptTimestamp || Date.now() + 3000,
singleJobInQueue: true,
currentRetry,
});
}
public async run() {
// blablha do everything from the notion page, and if success, return true.
console.warn(`running job ${this.jobType} with id:"${this.identifier}" `);
await sleepFor(5000);
console.warn(
`running job ${this.jobType} with id:"${this.identifier}" done and returning failed `
);
return false;
}
public serializeJob(): SerializedPersistedJob {
const fromParent = super.serializeBase();
return fromParent;
}
}