Skip to content

Commit

Permalink
Add better logging and reload every 3 hours (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajxu2 authored Nov 9, 2024
1 parent 859d8fe commit ae07487
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
Binary file modified bun.lockb
Binary file not shown.
9 changes: 3 additions & 6 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const PORT = process.env.PORT ?? 5010;
let cachedLocations: ILocation[];

async function reload(): Promise<void> {
console.log("Loading Dining API...");
const now = new Date();
console.log(`Reloading Dining API: ${now}`);
const parser = new DiningParser();
const locations = await parser.process();
if (
Expand Down Expand Up @@ -67,11 +68,7 @@ app.get("/locations/time/:day/:hour/:min", ({ params: { day, hour, min } }) => {
// Cache TTL: 3 hours
const interval = 1000 * 60 * 60 * 3;
setInterval(() => {
const today = new Date();
const dayOfWeek = today.getDay();
if (dayOfWeek === 6) {
reload().catch(console.error);
}
reload().catch(console.error);
}, interval);

reload().then(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/utils/requestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export async function getHTMLResponse(
retriesLeft = 4
): Promise<string> {
try {
console.log(`Scraping ${url}`);
const response = await axios.get(url.toString());
console.log({"message": `Scraped ${url}`, "html": response.data, "url": url.toString()});
return response.data;
} catch (err) {
if (!IS_TESTING) console.error(err);
Expand Down
1 change: 0 additions & 1 deletion src/utils/timeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ export function sortAndMergeTimeRanges(timeRanges: ITimeRange[]) {
mergedRanges.push(timeRange);
}
}
console.log(timeRanges, mergedRanges);
return mergedRanges;
}

0 comments on commit ae07487

Please sign in to comment.