Skip to content

Commit

Permalink
fix: allow failure in polling due to proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee committed Feb 26, 2024
1 parent b030c03 commit 509a6af
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/lib/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,28 @@ class Watcher {
let index = 0;
const od = this.zincDate.to(d);

let failureCount = 0;

while (true) {
const currentTime = Date.now();
const elapsedTime = currentTime - startTime;
if (elapsedTime >= loopDuration) break;
try {
const currentTime = Date.now();
const elapsedTime = currentTime - startTime;
if (elapsedTime >= loopDuration) break;

// run the searcher
const sch = await a.Search();
const timing: Record<string, number> = {};
for (const s of sch) timing[s.departure_time] = s.available_seats;
const key = `ktmb:schedule:${f}:${od}`;
const _ = await this.redis.publish(key, JSON.stringify(timing));
// run the searcher
const sch = await a.Search();
const timing: Record<string, number> = {};
for (const s of sch) timing[s.departure_time] = s.available_seats;
const key = `ktmb:schedule:${f}:${od}`;
const _ = await this.redis.publish(key, JSON.stringify(timing));
} catch (e) {
this.logger.error({ error: e }, "Failed to poll schedule");
failureCount++;
if (failureCount > 10) {
this.logger.error("Failed to poll schedule too many times, exiting");
throw e;
}
}
}
this.logger.info({ index: index++ }, "Watch complete");
}
Expand Down

0 comments on commit 509a6af

Please sign in to comment.