Add support for cron expressions for scheduling timer functions

This commit is contained in:
Peter Stockings
2025-11-27 15:51:15 +11:00
parent f3c2664b31
commit 3f9fa79515
7 changed files with 152 additions and 44 deletions

View File

@@ -39,6 +39,7 @@ const Editor = {
this.triggerType = vnode.attrs.triggerType || "interval";
this.frequencyMinutes = vnode.attrs.frequencyMinutes || 60;
this.runDate = vnode.attrs.runDate || "";
this.cronExpression = vnode.attrs.cronExpression || "";
this.showTimerSettings = vnode.attrs.showTimerSettings === true;
this.cancelUrl = vnode.attrs.cancelUrl || "/dashboard/http_functions";
this.isEnabled = vnode.attrs.isEnabled !== false;
@@ -243,6 +244,7 @@ const Editor = {
? parseInt(this.frequencyMinutes)
: null,
run_date: this.triggerType === "date" ? this.runDate : null,
cron_expression: this.triggerType === "cron" ? this.cronExpression : null,
is_enabled: this.isEnabled,
description: this.description,
runtime: this.runtime,
@@ -869,6 +871,7 @@ const Editor = {
},
[
m("option", { value: "interval" }, "Interval"),
m("option", { value: "cron" }, "Cron Expression"),
m("option", { value: "date" }, "Specific Date"),
]
),
@@ -893,6 +896,37 @@ const Editor = {
(this.frequencyMinutes = e.target.value),
}),
])
: this.triggerType === "cron"
? m("div", { class: "flex flex-col space-y-2" }, [
m(
"label",
{
class:
"text-sm font-medium text-gray-700 dark:text-gray-300",
},
"Cron Expression"
),
m("input[type=text]", {
class:
"bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-lg px-3 py-2 font-mono text-sm",
placeholder: "0 9 * * * (Daily at 9 AM)",
value: this.cronExpression,
oninput: (e) => (this.cronExpression = e.target.value),
}),
m(
"p",
{ class: "text-xs text-gray-500 dark:text-gray-400" },
[
"Examples: ",
m("code", { class: "bg-gray-100 dark:bg-gray-800 px-1 rounded" }, "0 9 * * *"),
" (9 AM daily), ",
m("code", { class: "bg-gray-100 dark:bg-gray-800 px-1 rounded" }, "*/15 * * * *"),
" (every 15 min), ",
m("code", { class: "bg-gray-100 dark:bg-gray-800 px-1 rounded" }, "0 0 * * MON"),
" (Mon midnight)",
]
),
])
: m("div", { class: "flex flex-col space-y-2" }, [
m(
"label",