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", {
|
logger.debug("enqueuing scheduled event", {
|
||||||
scheduleSourceId: scheduleSource.id,
|
scheduleSource,
|
||||||
scheduleTime,
|
scheduleTime,
|
||||||
lastTimestamp: scheduleSource.lastEventTimestamp,
|
lastTimestamp: scheduleSource.lastEventTimestamp,
|
||||||
});
|
});
|
||||||
@@ -61,6 +61,7 @@ export class NextScheduledEventService {
|
|||||||
runAt: scheduleTime,
|
runAt: scheduleTime,
|
||||||
queueName: `scheduler:${scheduleSource.environmentId}`,
|
queueName: `scheduler:${scheduleSource.environmentId}`,
|
||||||
tx,
|
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);
|
const service = new NextScheduledEventService(tx);
|
||||||
|
|
||||||
await service.call(scheduleSource.id);
|
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/general";
|
||||||
import "@/jobs/slack";
|
import "@/jobs/slack";
|
||||||
import "@/jobs/logging";
|
import "@/jobs/logging";
|
||||||
|
import "@/jobs/schedules";
|
||||||
import { createPagesRoute } from "@trigger.dev/nextjs";
|
import { createPagesRoute } from "@trigger.dev/nextjs";
|
||||||
|
|
||||||
const { handler, config } = createPagesRoute(client);
|
const { handler, config } = createPagesRoute(client);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^5.2.0",
|
"chalk": "^5.2.0",
|
||||||
|
"cronstrue": "^2.21.0",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"evt": "^2.4.13",
|
"evt": "^2.4.13",
|
||||||
"get-caller-file": "^2.0.5",
|
"get-caller-file": "^2.0.5",
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
CronOptions,
|
CronOptions,
|
||||||
EventExample,
|
|
||||||
IntervalOptions,
|
IntervalOptions,
|
||||||
ScheduleMetadata,
|
ScheduleMetadata,
|
||||||
ScheduledPayload,
|
ScheduledPayload,
|
||||||
@@ -11,6 +10,7 @@ import {
|
|||||||
import { Job } from "../job";
|
import { Job } from "../job";
|
||||||
import { TriggerClient } from "../triggerClient";
|
import { TriggerClient } from "../triggerClient";
|
||||||
import { EventSpecification, Trigger } from "../types";
|
import { EventSpecification, Trigger } from "../types";
|
||||||
|
import cronstrue from "cronstrue";
|
||||||
|
|
||||||
type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
|
type ScheduledEventSpecification = EventSpecification<ScheduledPayload>;
|
||||||
|
|
||||||
@@ -76,6 +76,10 @@ export class CronTrigger implements Trigger<ScheduledEventSpecification> {
|
|||||||
constructor(private options: CronOptions) {}
|
constructor(private options: CronOptions) {}
|
||||||
|
|
||||||
get event() {
|
get event() {
|
||||||
|
const humanReadable = cronstrue.toString(this.options.cron, {
|
||||||
|
throwExceptionOnParseError: false,
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: "trigger.scheduled",
|
name: "trigger.scheduled",
|
||||||
title: "Cron Schedule",
|
title: "Cron Schedule",
|
||||||
@@ -85,9 +89,13 @@ export class CronTrigger implements Trigger<ScheduledEventSpecification> {
|
|||||||
parsePayload: ScheduledPayloadSchema.parse,
|
parsePayload: ScheduledPayloadSchema.parse,
|
||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
label: "Expression",
|
label: "cron",
|
||||||
text: this.options.cron,
|
text: this.options.cron,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Schedule",
|
||||||
|
text: humanReadable,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+2
@@ -811,6 +811,7 @@ importers:
|
|||||||
'@types/uuid': ^9.0.0
|
'@types/uuid': ^9.0.0
|
||||||
'@types/ws': ^8.5.3
|
'@types/ws': ^8.5.3
|
||||||
chalk: ^5.2.0
|
chalk: ^5.2.0
|
||||||
|
cronstrue: ^2.21.0
|
||||||
debug: ^4.3.4
|
debug: ^4.3.4
|
||||||
evt: ^2.4.13
|
evt: ^2.4.13
|
||||||
get-caller-file: ^2.0.5
|
get-caller-file: ^2.0.5
|
||||||
@@ -830,6 +831,7 @@ importers:
|
|||||||
zod-to-json-schema: ^3.20.2
|
zod-to-json-schema: ^3.20.2
|
||||||
dependencies:
|
dependencies:
|
||||||
chalk: 5.2.0
|
chalk: 5.2.0
|
||||||
|
cronstrue: 2.21.0
|
||||||
debug: 4.3.4
|
debug: 4.3.4
|
||||||
evt: 2.4.13
|
evt: 2.4.13
|
||||||
get-caller-file: 2.0.5
|
get-caller-file: 2.0.5
|
||||||
|
|||||||
Reference in New Issue
Block a user