chore: add retry count to subs

This commit is contained in:
Anthony Potdevin 2022-02-23 15:32:15 +01:00
parent b6076b58d9
commit e5442d1c21
No known key found for this signature in database
GPG key ID: 4403F1DFBE779457

View file

@ -40,6 +40,7 @@ const saveBackupMutation = gql`
@Injectable()
export class SubService implements OnApplicationBootstrap {
subscriptions = [];
retryCount = 0;
constructor(
private accountsService: AccountsService,
@ -476,12 +477,22 @@ export class SubService implements OnApplicationBootstrap {
} else {
this.logger.error('AsyncAuto results:', results);
}
const message = `Restarting subscription after ${restartSubscriptionTimeMs} ms`;
this.retryCount = this.retryCount + 1;
if (this.retryCount >= 4) {
next('Max retries attempted');
return;
}
const retryTime = restartSubscriptionTimeMs * this.retryCount;
const message = `Restarting subscription (Retry: ${this.retryCount}) after ${retryTime} ms`;
this.logger.warn(message);
setTimeout(async () => {
this.logger.warn('Restarting...');
next(null, 'retry');
}, restartSubscriptionTimeMs);
}, retryTime);
}
);
},