feat: add watchdog timer to detect and recover from hung API requests
Deploy Iddaai Backend / build-and-deploy (push) Successful in 27s
Deploy Iddaai Backend / build-and-deploy (push) Successful in 27s
This commit is contained in:
@@ -43,6 +43,14 @@ export class FeederService {
|
||||
private readonly MAX_RETRIES = 50;
|
||||
private readonly DAILY_SYNC_TIME_ZONE = "Europe/Istanbul";
|
||||
|
||||
/** Watchdog heartbeat – updated on every match/date activity */
|
||||
public lastActivityAt: number = Date.now();
|
||||
|
||||
/** Call this to bump the heartbeat */
|
||||
private heartbeat(): void {
|
||||
this.lastActivityAt = Date.now();
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly scraperService: FeederScraperService,
|
||||
private readonly transformerService: FeederTransformerService,
|
||||
@@ -259,6 +267,7 @@ export class FeederService {
|
||||
): Promise<void> {
|
||||
const { onlyCompletedMatches = false, refreshExistingMatches = false } =
|
||||
options;
|
||||
this.heartbeat();
|
||||
this.logger.log(`[${sport}] 📅 Processing: ${dateString}`);
|
||||
|
||||
try {
|
||||
@@ -431,6 +440,7 @@ export class FeederService {
|
||||
refreshExistingMatches,
|
||||
);
|
||||
|
||||
this.heartbeat();
|
||||
if (result.success) {
|
||||
this.logger.log(
|
||||
`[${sport}] ✅ successful for ${match.id} ${match.homeTeam.name} vs ${match.awayTeam.name}`,
|
||||
@@ -443,6 +453,7 @@ export class FeederService {
|
||||
failedMatches.push(match);
|
||||
}
|
||||
} catch (e: any) {
|
||||
this.heartbeat();
|
||||
this.logger.warn(
|
||||
`[${sport}] Sequential error for ${match.id}: ${e.message}`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user