fix(workflow-engine-*): scheduled jobs interval (#11800)
**What**
Currently only cron pattern are supported by scheduled jobs, this can lead to issue. for example you set the pattern to execute every hours at minute 0 and second 0 (as it is expected to execute at exactly this constraint) but due to the moment it gets executed we our out of the second 0 then the job wont get executed until the next scheduled cron table execution.
With this pr we introduce the `interval` configuration which allows you the specify a delay between execution in ms (e.g every minute -> 60 * 1000 ms) which ensure that once a job is executed another one is scheduled for a minute later.
**Usage**
```ts
// jobs/job-1.ts
const thirtySeconds = 30 * 1000
export const config = {
name: "job-1",
schedule: {
interval: thirtySeconds
},
}
```
This commit is contained in:
committed by
GitHub
parent
e05491c24f
commit
fc652ea51e
@@ -11,7 +11,7 @@ import { ResourceLoader } from "../utils/resource-loader"
|
||||
|
||||
type CronJobConfig = {
|
||||
name: string
|
||||
schedule: string
|
||||
schedule: string | SchedulerOptions
|
||||
numberOfExecutions?: SchedulerOptions["numberOfExecutions"]
|
||||
}
|
||||
|
||||
|
||||
@@ -144,10 +144,6 @@ export type TransactionModelOptions = {
|
||||
}
|
||||
|
||||
export type SchedulerOptions = {
|
||||
/**
|
||||
* The cron expression to schedule the workflow execution.
|
||||
*/
|
||||
cron: string
|
||||
/**
|
||||
* Setting whether to allow concurrent executions (eg. if the previous execution is still running, should the new one be allowed to run or not)
|
||||
* By default concurrent executions are not allowed.
|
||||
@@ -158,7 +154,20 @@ export type SchedulerOptions = {
|
||||
* Optionally limit the number of executions for the scheduled workflow. If not set, the workflow will run indefinitely.
|
||||
*/
|
||||
numberOfExecutions?: number
|
||||
}
|
||||
} & (
|
||||
| {
|
||||
/**
|
||||
* The cron expression to schedule the workflow execution.
|
||||
*/
|
||||
cron: string
|
||||
}
|
||||
| {
|
||||
/**
|
||||
* The interval (in ms) to schedule the workflow execution.
|
||||
*/
|
||||
interval: number
|
||||
}
|
||||
)
|
||||
|
||||
export type TransactionModel = {
|
||||
id: string
|
||||
|
||||
@@ -24,9 +24,8 @@ class WorkflowScheduler {
|
||||
concurrency: "forbid",
|
||||
}
|
||||
: {
|
||||
cron: schedule.cron,
|
||||
concurrency: schedule.concurrency || "forbid",
|
||||
numberOfExecutions: schedule.numberOfExecutions,
|
||||
concurrency: "forbid",
|
||||
...schedule,
|
||||
}
|
||||
|
||||
await WorkflowScheduler.storage.schedule(workflow.id, normalizedSchedule)
|
||||
|
||||
Reference in New Issue
Block a user