apiVersion: capsule.dev/v0.1
kind: Capsule
name: f4c-scheduled-cleanup
version: 0.1.0
type: subsystem
purpose:
summary: 'A Cloudflare Scheduled Worker that periodically cleans up expired chat
rooms from Cloudflare KV and deactivates corresponding RealtimeKit meetings to
prevent resource leakage.
'
owns:
- Scheduled task execution logic
- Scanning and deleting expired room records from Cloudflare KV
- Deactivating RealtimeKit meetings associated with expired rooms
does_not_own:
- Real-time communication logic
- Bot logic
- Room creation or client-side authentication
interfaces:
provides:
- kind: event
name: scheduled_trigger
description: Responds to Cloudflare Worker scheduled events to perform cleanup.
requires:
- kind: env
name: ROOMS_KV
description: Cloudflare KV Namespace containing room metadata.
- kind: env
name: CF_API_TOKEN
description: Cloudflare API token for RealtimeKit API calls.
- kind: env
name: CF_ACCOUNT_ID
description: Cloudflare account ID for RealtimeKit API calls.
- kind: env
name: RTK_APP_ID
description: RealtimeKit application ID for deactivating meetings.
dependencies:
capsules:
- name: f4c-room-api
version: '>=0.1.0'
agent:
summary_for_ai: 'This capsule is a scheduled cleanup worker. Agents should focus
on optimizing KV queries, ensuring robust error handling for API calls, and verifying
that expired rooms are consistently removed. The `ROOM_MAX_AGE_MS` is a critical
parameter.
'
avoid:
- Introducing any real-time or interactive logic.
- Modifying the room expiry logic without coordinating with `f4c-room-api`.
verification:
invariants:
- Expired rooms must be removed from `ROOMS_KV`.
- Corresponding RealtimeKit meetings must be deactivated.
x-reuse:
notes: 'app/src/do/ScheduledHandler.ts: `ROOM_MAX_AGE_MS` is hardcoded. Assumes
Cloudflare RealtimeKit for meeting deactivation and the specific structure of
`RoomRecord` in `ROOMS_KV`.
'
x-reconstruct:
install: install.json