-
After a several hours, when enter the game with the same matchID, the game instance is still here. Can the server automatically delete unactivated game instance? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Currently the server deletes a match when all players use the boardgame.io/src/server/api.ts Lines 305 to 310 in d56728b In practice this may not happen reliably if a player closes a client before the |
Beta Was this translation helpful? Give feedback.
-
@delucis So could you please give me a specific way to make server automatically clean match instances every 24 hours? |
Beta Was this translation helpful? Give feedback.
-
I’ll leave the precise scheduling logic up to you — you could use a library like Please be careful with this! If your database connector doesn’t support the // Create and run the server as usual.
const { Server } = require('boardgame.io/server');
const db = new DbConnector();
const server = Server({
games: [game1, game2, ...],
db,
});
server.run(8000);
// Define clean-up method.
const day = 24 * 60 * 60 * 1000;
const cleanStaleMatches = async () => {
const weekAgo = Date.now() - 7 * day;
// Retrieve matchIDs for matches unchanged for > 1 week.
const staleMatchIDs = await db.listMatches({
where: {
updatedBefore: weekAgo,
},
});
// Delete matches one-by-one. Could also use a queue or parallel system here.
for (const id of staleMatchIDs) {
await db.wipe(id);
}
}
// Schedule clean-up.
setInterval(cleanStaleMatches, day); |
Beta Was this translation helpful? Give feedback.
Currently the server deletes a match when all players use the
leave
endpoint, making the room empty:boardgame.io/src/server/api.ts
Lines 305 to 310 in d56728b
In practice this may not happen reliably if a player closes a client before the
leave
request. It would probably be nice to add an option for some time-based clean-up now that matches containupdatedAt
metadata and an option to disable auto-deletion.