Job Queue: Don't wait unless it's our first time in verify loop

This commit is contained in:
Scott Nonnenberg 2022-04-12 12:41:12 -07:00 committed by GitHub
parent a013e43299
commit 8f630a52b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 0 deletions

View File

@ -214,8 +214,11 @@ export class ConversationJobQueue extends JobQueue<ConversationQueueJobData> {
let timeRemaining: number;
let shouldContinue: boolean;
let count = 0;
// eslint-disable-next-line no-constant-condition
while (true) {
count += 1;
log.info('calculating timeRemaining and shouldContinue...');
timeRemaining = timestamp + MAX_RETRY_TIME - Date.now();
// eslint-disable-next-line no-await-in-loop
@ -223,6 +226,7 @@ export class ConversationJobQueue extends JobQueue<ConversationQueueJobData> {
attempt,
log,
timeRemaining,
skipWait: count > 1,
});
if (!shouldContinue) {
break;

View File

@ -11,10 +11,12 @@ export async function commonShouldJobContinue({
attempt,
log,
timeRemaining,
skipWait,
}: Readonly<{
attempt: number;
log: LoggerType;
timeRemaining: number;
skipWait: boolean;
}>): Promise<boolean> {
if (timeRemaining <= 0) {
log.info("giving up because it's been too long");
@ -37,6 +39,10 @@ export async function commonShouldJobContinue({
return false;
}
if (skipWait) {
return true;
}
const sleepTime = exponentialBackoffSleepTime(attempt);
log.info(`sleeping for ${sleepTime}`);
await sleep(sleepTime);

View File

@ -29,6 +29,7 @@ export async function runReceiptJob({
attempt,
log,
timeRemaining,
skipWait: false,
});
if (!shouldContinue) {
return;

View File

@ -108,6 +108,7 @@ export async function runSyncJob({
attempt,
log,
timeRemaining,
skipWait: false,
});
if (!shouldContinue) {
return;

View File

@ -54,6 +54,7 @@ export class SingleProtoJobQueue extends JobQueue<SingleProtoJobData> {
attempt,
log,
timeRemaining,
skipWait: false,
});
if (!shouldContinue) {
return;