Skip to content

Commit

Permalink
chore: add retry count to subs
Browse files Browse the repository at this point in the history
  • Loading branch information
apotdevin committed Feb 23, 2022
1 parent b6076b5 commit e5442d1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/server/modules/sub/sub.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const saveBackupMutation = gql`
@Injectable()
export class SubService implements OnApplicationBootstrap {
subscriptions = [];
retryCount = 0;

constructor(
private accountsService: AccountsService,
Expand Down Expand Up @@ -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);
}
);
},
Expand Down

0 comments on commit e5442d1

Please sign in to comment.