Allow scheduled jobs to have their schedule updated
Also added human readable cron property to cron triggers
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@trigger.dev/sdk": patch
|
||||
---
|
||||
|
||||
Added human readable cron expression property to cron triggers
|
||||
@@ -43,7 +43,7 @@ export class NextScheduledEventService {
|
||||
);
|
||||
|
||||
logger.debug("enqueuing scheduled event", {
|
||||
scheduleSourceId: scheduleSource.id,
|
||||
scheduleSource,
|
||||
scheduleTime,
|
||||
lastTimestamp: scheduleSource.lastEventTimestamp,
|
||||
});
|
||||
@@ -61,6 +61,7 @@ export class NextScheduledEventService {
|
||||
runAt: scheduleTime,
|
||||
queueName: `scheduler:${scheduleSource.environmentId}`,
|
||||
tx,
|
||||
jobKey: `scheduled:${scheduleSource.id}`,
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ export class RegisterScheduleSourceService {
|
||||
},
|
||||
});
|
||||
|
||||
if (scheduleSource.active && !scheduleSource.workerJobId) {
|
||||
if (scheduleSource.active) {
|
||||
const service = new NextScheduledEventService(tx);
|
||||
|
||||
await service.call(scheduleSource.id);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { client } from "@/trigger";
|
||||
import { Job, cronTrigger } from "@trigger.dev/sdk";
|
||||
|
||||
new Job(client, {
|
||||
id: "test-cron-schedule-2",
|
||||
name: "Test Cron Schedule 2",
|
||||
version: "0.0.1",
|
||||
logLevel: "debug",
|
||||
trigger: cronTrigger({
|
||||
cron: "*/5 * * * *",
|
||||
}),
|
||||
run: async (payload, io, ctx) => {
|
||||
await io.logger.debug("Hello cron schedule 2a", {
|
||||
payload,
|
||||
payload2: payload,
|
||||
});
|
||||
},
|
||||
});
|
||||
@@ -5,6 +5,7 @@ import "@/jobs/resend";
|
||||
import "@/jobs/general";
|
||||
import "@/jobs/slack";
|
||||
import "@/jobs/logging";
|
||||
import "@/jobs/schedules";
|
||||
import { createPagesRoute } from "@trigger.dev/nextjs";
|
||||
|
||||
const { handler, config } = createPagesRoute(client);
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"chalk": "^5.2.0",
|
||||
"cronstrue": "^2.21.0",
|
||||
"debug": "^4.3.4",
|
||||
"evt": "^2.4.13",
|
||||
"get-caller-file": "^2.0.5",
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
CronOptions,
|
||||
EventExample,
|
||||
IntervalOptions,
|
||||
ScheduleMetadata,
|
||||
ScheduledPayload,
|
||||
@@ -11,6 +10,7 @@ import {
|
||||
import { Job } from "../job";
|
||||
import { TriggerClient } from "../triggerClient";
|
||||
import { EventSpecification, Trigger } from "../types";
|
||||
import cronstrue from "cronstrue";
|
||||
|
||||
type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
|
||||
|
||||
@@ -76,6 +76,10 @@ export class CronTrigger implements Trigger<ScheduledEventSpecification> {
|
||||
constructor(private options: CronOptions) {}
|
||||
|
||||
get event() {
|
||||
const humanReadable = cronstrue.toString(this.options.cron, {
|
||||
throwExceptionOnParseError: false,
|
||||
});
|
||||
|
||||
return {
|
||||
name: "trigger.scheduled",
|
||||
title: "Cron Schedule",
|
||||
@@ -85,9 +89,13 @@ export class CronTrigger implements Trigger<ScheduledEventSpecification> {
|
||||
parsePayload: ScheduledPayloadSchema.parse,
|
||||
properties: [
|
||||
{
|
||||
label: "Expression",
|
||||
label: "cron",
|
||||
text: this.options.cron,
|
||||
},
|
||||
{
|
||||
label: "Schedule",
|
||||
text: humanReadable,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
Generated
+2
@@ -811,6 +811,7 @@ importers:
|
||||
'@types/uuid': ^9.0.0
|
||||
'@types/ws': ^8.5.3
|
||||
chalk: ^5.2.0
|
||||
cronstrue: ^2.21.0
|
||||
debug: ^4.3.4
|
||||
evt: ^2.4.13
|
||||
get-caller-file: ^2.0.5
|
||||
@@ -830,6 +831,7 @@ importers:
|
||||
zod-to-json-schema: ^3.20.2
|
||||
dependencies:
|
||||
chalk: 5.2.0
|
||||
cronstrue: 2.21.0
|
||||
debug: 4.3.4
|
||||
evt: 2.4.13
|
||||
get-caller-file: 2.0.5
|
||||
|
||||
Reference in New Issue
Block a user