Skip to content

Commit

Permalink
Add scheduler to trigger updater
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Dec 21, 2024
1 parent c958979 commit 746959d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
26 changes: 12 additions & 14 deletions src/config/schedulers.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// TODO: Overlapping schedulers. Will clean up
export const schedulers = {
cars: {
schedule: "*/60 0-10 * * 1-5",
},
coe: {
schedule: "*/60 0-10 * * 1-5",
},
"coe-1st-bidding": {
schedule: "*/60 0-10 * * 4,5",
},
"coe-2nd-bidding": {
schedule: "*/60 0-10 * * 4,5",
},
type SchedulerName = "cars" | "coe";

type ScheduleOptions =
| string
| {
pattern: string;
timezone?: string;
};

export const schedulers: Record<SchedulerName, ScheduleOptions> = {
cars: "*/60 0-10 * * 1-5",
coe: "*/60 0-10 * * 1-5",
};
6 changes: 4 additions & 2 deletions src/trigger/update-cars.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { schedulers } from "@/config/schedulers";
import { updateCars } from "@/lib/updateCars";
import { logger, task } from "@trigger.dev/sdk/v3";
import { logger, schedules } from "@trigger.dev/sdk/v3";

export const updateCarsTask = task({
export const updateCarsTask = schedules.task({
id: "update-cars",
cron: schedulers.cars,
run: async (payload: any, { ctx }) => {
try {
logger.log("Starting Cars Update Task", { payload, ctx });
Expand Down
6 changes: 4 additions & 2 deletions src/trigger/update-coe.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { schedulers } from "@/config/schedulers";
import { updateCOE } from "@/lib/updateCOE";
import { logger, task } from "@trigger.dev/sdk/v3";
import { logger, schedules } from "@trigger.dev/sdk/v3";

export const updateCOETask = task({
export const updateCOETask = schedules.task({
id: "update-coe",
cron: schedulers.coe,
run: async (payload: any, { ctx }) => {
try {
logger.log("Starting COE Update Task", { payload, ctx });
Expand Down

0 comments on commit 746959d

Please sign in to comment.