From 90b244e0eb16c5bdde068864e36038eaac078466 Mon Sep 17 00:00:00 2001 From: Ru Chern Chong Date: Wed, 13 Dec 2023 23:10:37 +0800 Subject: [PATCH] Add scheduler --- sst.config.ts | 2 ++ stacks/Scheduler.ts | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 stacks/Scheduler.ts diff --git a/sst.config.ts b/sst.config.ts index aa773b2..f9b0498 100644 --- a/sst.config.ts +++ b/sst.config.ts @@ -1,5 +1,6 @@ import { SSTConfig } from "sst"; import { api } from "./stacks/MyStack"; +import { scheduler } from "./stacks/Scheduler"; export default { config(_input) { @@ -10,5 +11,6 @@ export default { }, stacks(app) { app.stack(api); + app.stack(scheduler); }, } satisfies SSTConfig; diff --git a/stacks/Scheduler.ts b/stacks/Scheduler.ts new file mode 100644 index 0000000..309d7b7 --- /dev/null +++ b/stacks/Scheduler.ts @@ -0,0 +1,11 @@ +import { Cron, StackContext } from "sst/constructs"; + +const cronScheduler = `0/60 12-18 ? * MON-FRI *`; + +export const scheduler = ({ stack }: StackContext) => { + new Cron(stack, "cron", { + schedule: `cron(${cronScheduler})`, + job: "packages/functions/src/datasets.updater", + enabled: stack.stage === "prod", + }); +};