Delayed publish
Publish a post, send an email, or release content at a specific future time.
Use this to
- Schedule a blog post to go live next Tuesday at 9am
- Send a marketing email at a specific time in the recipient's timezone
- Release a feature flag at a coordinated launch moment
- Queue a changelog announcement to go out at the start of business hours
Code
Schedule for an exact time
await dk.schedule("publish-post", { key: post.id, at: post.publishAt, // a Date in the future });
Reschedule or cancel before it fires
// editor moved the time await dk.schedule("publish-post", { key: post.id, at: post.publishAt, onDuplicate: "replace", }); // or pull it entirely await dk.unschedule("publish-post", post.id);
When the time comes, read current state and publish
dk.handle("publish-post", async ({ key }) => { const post = await db.posts.find(key); if (post.status !== "scheduled") return; // already published or pulled await db.posts.update(key, { status: "published" }); await cdn.invalidate(post.slug); });
npm install delaykit