Deferred cleanup
Fire-and-forget maintenance. Schedule it once, let it run.
Use this to
- Delete a soft-deleted record one hour after the user confirmed deletion
- Archive a video upload one hour after transcoding finishes
- Tear down a sandbox environment 24 hours after it was created
- Remove temporary export files from storage after their download link expires
Code
Schedule once, walk away
// no cancel, no state check — the handler always runs await dk.schedule("cleanup-upload", { key: "upload_abc", delay: "1h", });
When the time comes, just delete
dk.handle("cleanup-upload", async ({ key }) => { await storage.delete(key); await db.uploads.delete(key); });
npm install delaykit