Skip to content

Commit

Permalink
Increase timeout and concurrency of archiving stale games
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzhang committed Dec 23, 2024
1 parent 3592b11 commit f3f482a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,18 +492,21 @@ export const fetchStaleGame = functions.https.onCall(async (data, context) => {
});

/** Archive stale game states to GCS for cost savings. */
export const archiveStaleGames = functions.pubsub
.schedule("every 1 hours")
export const archiveStaleGames = functions
.runWith({ timeoutSeconds: 540, memory: "1GB" })
.pubsub.schedule("every 1 hours")
.onRun(async (context) => {
const cutoff = Date.now() - 30 * 86400 * 1000; // 30 days ago
const queue = new PQueue({ concurrency: 50 });

for await (const [gameId] of databaseIterator("gameData")) {
const game = await getDatabase().ref(`games/${gameId}`).get();
if (game.val().createdAt < cutoff) {
console.log(`Archiving stale game state for ${gameId}`);
await queue.add(() => archiveGameState(gameId));
}
await queue.add(async () => {
const game = await getDatabase().ref(`games/${gameId}`).get();
if (game.val().createdAt < cutoff) {
console.log(`Archiving stale game state for ${gameId}`);
await archiveGameState(gameId);
}
});
}

await queue.onIdle();
Expand Down

0 comments on commit f3f482a

Please sign in to comment.