-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.ts
More file actions
50 lines (43 loc) · 1.29 KB
/
Copy pathmain.ts
File metadata and controls
50 lines (43 loc) · 1.29 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
39
40
41
42
43
44
45
46
47
48
49
50
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.iterable" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" />;
import "@std/dotenv/load";
import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts";
import config from "./fresh.config.ts";
import { CronTime } from "npm:cron-time-generator";
import { pollWeeWooOpsSQSMessages, sendReport } from "./lib/cron_tasks.ts";
import { asyncLocalStorage, log } from "./lib/logger.ts";
/**
* Wrap a cron job in a request ID and logging context
*/
function prepare<T extends () => Promise<void>>(fn: T) {
return () => {
return asyncLocalStorage.run(crypto.randomUUID(), async () => {
if (Deno.env.get("STAGE") !== "PROD") {
log.info("skipping cron because env is not prod");
return;
}
const start = Date.now();
log.info("cron job started");
await fn();
log.info("cron job finished", {
duration: Date.now() - start,
});
});
};
}
Deno.cron(
"Poll WeeWoo Ops SQS Messages",
CronTime.every(15).minutes(),
prepare(pollWeeWooOpsSQSMessages),
);
Deno.cron(
"Weekly Question Report",
CronTime.everySaturdayAt(9),
prepare(sendReport),
);
await start(manifest, config);