Schedule a follow-up
Run a task after a period of user inactivity. Each call resets the clock.
Use this to
- Send a re-engagement email 3 days after a user's last login
- Remind a team member about an unreplied thread after 48 hours
- Nudge a user to finish a form they started but haven't submitted in 24 hours
- Prompt a seller to update their listing if they haven't edited it in a week
Code
Debounce on every user activity
// safe to call from middleware on every request — debounce // only updates a row in Postgres, no scheduling churn await dk.debounce("follow-up", { key: user.id, wait: "3d", });
When the time comes, send the follow-up
dk.handle("follow-up", async ({ key }) => { const user = await db.users.find(key); if (wasActiveRecently(user)) return; // safety check await sendReengagementEmail(user.email); });
npm install delaykit