Operations in wizwar's shape: the determinism gate, backups, the rollup and the pulse
Every deploy first replays every production ledger with the engine about to ship. The droplet gains a nightly rollup of counts and a nightly backup to Spaces, a pulse script the pulse skill reads, rate limits on opening rooms and taking seats, and eviction of idle rooms from memory with reload from their ledgers on the next visit. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0141G6xqLeNRYEtviLWSB5Up
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
885dcf56e6
commit
9bd203ae60
+26
-1
@@ -71,11 +71,36 @@ export class Rooms {
|
||||
}
|
||||
|
||||
get(id: string): Room {
|
||||
const room = this.rooms.get(id) ?? this.rooms.get(normalizeCode(id));
|
||||
const room = this.rooms.get(id) ?? this.rooms.get(normalizeCode(id)) ?? this.load(normalizeCode(id));
|
||||
if (!room) throw new RoomError('No duel answers to that code.', 404);
|
||||
return room;
|
||||
}
|
||||
|
||||
/** A room evicted from memory comes back from its ledger on the next visit. */
|
||||
private load(id: string): Room | undefined {
|
||||
if (!/^[A-Z0-9]{4}$/.test(id)) return undefined;
|
||||
const room = replay(id, this.store.read(id));
|
||||
if (room) this.rooms.set(id, room);
|
||||
return room ?? undefined;
|
||||
}
|
||||
|
||||
/** Forget rooms nobody has touched or watched for a while; their ledgers stay on disk. */
|
||||
evictIdle(olderThanMs: number, now = Date.now()): number {
|
||||
let n = 0;
|
||||
for (const [id, room] of this.rooms) {
|
||||
if (now - room.updatedAt < olderThanMs) continue;
|
||||
if ((this.listeners.get(id)?.size ?? 0) > 0) continue;
|
||||
this.rooms.delete(id);
|
||||
n += 1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/** How many rooms are held in memory. */
|
||||
get loaded(): number {
|
||||
return this.rooms.size;
|
||||
}
|
||||
|
||||
/** The seat a token unlocks. */
|
||||
seatOf(room: Room, token: string | undefined): Seat {
|
||||
const seat = room.seats.find((s) => !s.bot && s.token === token);
|
||||
|
||||
Reference in New Issue
Block a user