add expiry push notifications
Deploy to Cloudflare Pages / deploy (push) Successful in 1m27s

This commit is contained in:
2026-08-24 13:07:38 +00:00 Unverified
parent 76782541b0
commit e06cd700f6
24 changed files with 3001 additions and 12 deletions
+30 -1
View File
@@ -6,8 +6,10 @@ import {
type Env = {
GUIDE_JOB_URL: string;
NOTIFICATION_JOB_URL: string;
GUIDE_JOB_SECRET: string;
RECOMMENDATION_WORKFLOW: Workflow;
NOTIFICATION_WORKFLOW: Workflow;
};
export class RecommendationWorkflow extends WorkflowEntrypoint<Env> {
@@ -32,11 +34,38 @@ export class RecommendationWorkflow extends WorkflowEntrypoint<Env> {
}
}
export class NotificationWorkflow extends WorkflowEntrypoint<Env> {
async run(_event: WorkflowEvent<unknown>, step: WorkflowStep) {
return step.do(
"send due expiry notifications",
{
retries: { limit: 3, delay: "2 minutes", backoff: "exponential" },
timeout: "5 minutes",
},
async () => {
const response = await fetch(this.env.NOTIFICATION_JOB_URL, {
method: "POST",
headers: { authorization: `Bearer ${this.env.GUIDE_JOB_SECRET}` },
});
if (!response.ok) {
throw new Error(`Notification endpoint failed (${response.status})`);
}
return response.json<{ checked: number; sent: number }>();
},
);
}
}
export default {
fetch() {
return Response.json({ service: "hotfridge-recommendation-workflow" });
},
async scheduled(_controller: ScheduledController, env: Env, ctx: ExecutionContext) {
ctx.waitUntil(env.RECOMMENDATION_WORKFLOW.create({ params: {} }));
ctx.waitUntil(
Promise.all([
env.RECOMMENDATION_WORKFLOW.create({ params: {} }),
env.NOTIFICATION_WORKFLOW.create({ params: {} }),
]),
);
},
};