mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-08-01 06:37:08 +00:00
* Revert "Revert "Allow to launch server without Redis (#119)" (#133)" This reverts commit 18065f965215c32b4b66e13246a6a54977088518. * Default to REDIS_URL env var for store host
26 lines
830 B
JavaScript
26 lines
830 B
JavaScript
import getStore from './store';
|
|
|
|
export async function pollForInactiveRooms() {
|
|
const store = getStore();
|
|
|
|
console.log('Checking for inactive rooms...');
|
|
const rooms = (await store.getAll('rooms')) || {};
|
|
console.log(`${Object.keys(rooms).length} rooms found`);
|
|
|
|
Object.keys(rooms).forEach(async (roomId) => {
|
|
const room = JSON.parse(rooms[roomId]);
|
|
const timeSinceUpdatedInSeconds = (Date.now() - room.updatedAt) / 1000;
|
|
const timeSinceUpdatedInDays = Math.round(
|
|
timeSinceUpdatedInSeconds / 60 / 60 / 24
|
|
);
|
|
if (timeSinceUpdatedInDays > 7) {
|
|
console.log(
|
|
`Deleting roomId ${roomId} which hasn't been used in ${timeSinceUpdatedInDays} days`
|
|
);
|
|
await store.del('rooms', roomId);
|
|
}
|
|
});
|
|
|
|
setTimeout(pollForInactiveRooms, 1000 * 60 * 60 * 12); // every 12 hours
|
|
}
|