-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-worker.ts
More file actions
38 lines (34 loc) · 1.16 KB
/
Copy pathcustom-worker.ts
File metadata and controls
38 lines (34 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// The OpenNext worker is generated before Wrangler bundles this entrypoint.
// @ts-expect-error Generated module is unavailable during the Next.js typecheck.
import handler from "./.open-next/worker.js";
type VohaCloudflareEnv = CloudflareEnv & {
VOHA_CRON_SECRET: string;
};
export default {
fetch: handler.fetch,
async scheduled(
controller: ScheduledController,
env: VohaCloudflareEnv,
ctx: ExecutionContext,
) {
const scheduledAt = new Date(controller.scheduledTime);
const maintenance =
scheduledAt.getUTCHours() === 3 && scheduledAt.getUTCMinutes() === 17;
const response = await handler.fetch(
new Request(`https://voha.internal/api/internal/publications/run${maintenance ? "?maintenance=1" : ""}`, {
method: "POST",
headers: { "x-voha-cron-secret": env.VOHA_CRON_SECRET },
}),
env,
ctx,
);
if (!response.ok) {
console.error(JSON.stringify({
event: "operational_scheduled_handler_failed",
status: response.status,
maintenance,
}));
throw new Error("operational_scheduled_handler_failed");
}
},
} satisfies ExportedHandler<VohaCloudflareEnv>;