Skip to content

Commit 9da3ad7

Browse files
authored
Update index.ts
1 parent b71a229 commit 9da3ad7

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

backend/src/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@ import { eventInfo, eventInfoMutex, fetchEvents } from "./data/eventData";
99
dotenv.config();
1010

1111
(async () => {
12-
try {
13-
const events = await fetchEvents();
14-
eventInfoMutex.runExclusive(() => eventInfo.push(...events));
15-
console.log("Events fetched successfully");
16-
} catch (error) {
17-
// do we ungracefully bail out here???
18-
// could just load from a backup file instead
19-
console.error("Error fetching events on startup:", error);
20-
}
12+
setInterval(() => {
13+
try {
14+
const events = await fetchEvents();
15+
eventInfoMutex.runExclusive(() => {
16+
eventInfo.length = 0;
17+
eventInfo.push(...events);
18+
});
19+
console.log("Events fetched successfully");
20+
} catch (error) {
21+
// do we ungracefully bail out here???
22+
// could just load from a backup file instead
23+
console.error("Error fetching events:", error);
24+
}
25+
}, 30 * 60 * 1000);
2126

2227
const app: Express = express();
2328
const port = process.env.PORT || 9000;

0 commit comments

Comments
 (0)