Adding cron presets to automations
This commit is contained in:
parent
c3dc5bae76
commit
a781239632
|
@ -10,6 +10,7 @@
|
|||
import CodeEditorModal from "./CodeEditorModal.svelte"
|
||||
import QuerySelector from "./QuerySelector.svelte"
|
||||
import QueryParamSelector from "./QueryParamSelector.svelte"
|
||||
import CronBuilder from "./CronBuilder.svelte"
|
||||
import Editor from "components/integration/QueryEditor.svelte"
|
||||
|
||||
export let block
|
||||
|
@ -76,6 +77,8 @@
|
|||
/>
|
||||
{:else if value.customType === "query"}
|
||||
<QuerySelector bind:value={block.inputs[key]} />
|
||||
{:else if value.customType === "cron"}
|
||||
<CronBuilder bind:value={block.inputs[key]} />
|
||||
{:else if value.customType === "queryParams"}
|
||||
<QueryParamSelector bind:value={block.inputs[key]} {bindings} />
|
||||
{:else if value.customType === "table"}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
<script>
|
||||
import { Button, Select, Label, Heading, Input } from "@budibase/bbui"
|
||||
|
||||
export let value
|
||||
|
||||
let presets = false
|
||||
|
||||
const CRON_EXPRESSIONS = [
|
||||
{
|
||||
label: "Every Minute",
|
||||
value: "* * * * *"
|
||||
},
|
||||
{
|
||||
label: "Every Hour",
|
||||
value: "0 * * * *"
|
||||
},
|
||||
{
|
||||
label: "Every Morning at 8AM",
|
||||
value: "0 8 * * *"
|
||||
},
|
||||
{
|
||||
label: "Every Night at Midnight",
|
||||
value: "0 0 * * *"
|
||||
},
|
||||
{
|
||||
label: "Every Budibase Reboot",
|
||||
value: "@reboot"
|
||||
},
|
||||
]
|
||||
</script>
|
||||
|
||||
<div class="block-field">
|
||||
<Input bind:value />
|
||||
|
||||
<div class="presets">
|
||||
<Button on:click={() => (presets = !presets)}>{presets ? "Hide" : "Show"} Presets</Button>
|
||||
{#if presets}
|
||||
<Select bind:value secondary extraThin label="Presets" options={CRON_EXPRESSIONS} />
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.presets {
|
||||
margin-top: var(--spacing-m);
|
||||
}
|
||||
.block-field {
|
||||
padding-top: var(--spacing-s);
|
||||
}
|
||||
</style>
|
|
@ -55,13 +55,15 @@ async function checkForCronTriggers({ appId, oldAuto, newAuto }) {
|
|||
|
||||
const cronTriggerRemoved =
|
||||
isCronTrigger(oldAuto) && !isCronTrigger(newAuto) && oldTrigger.cronJobId
|
||||
const cronTriggerAdded = !isCronTrigger(oldAuto) && isCronTrigger(newAuto)
|
||||
const cronTriggerDeactivated = !newAuto.live && oldAuto.live
|
||||
|
||||
if (cronTriggerRemoved) {
|
||||
const cronTriggerActivated = newAuto.live && !oldAuto.live
|
||||
|
||||
if (cronTriggerRemoved || cronTriggerDeactivated) {
|
||||
await triggers.automationQueue.removeRepeatableByKey(oldTrigger.cronJobId)
|
||||
}
|
||||
// need to create cron job
|
||||
else if (cronTriggerAdded) {
|
||||
else if (isCronTrigger(newAuto) && cronTriggerActivated) {
|
||||
const job = await triggers.automationQueue.add(
|
||||
{ automation: newAuto, event: { appId } },
|
||||
{ repeat: { cron: newTrigger.inputs.cron } }
|
||||
|
|
|
@ -201,7 +201,7 @@ const BUILTIN_DEFINITIONS = {
|
|||
name: "Cron Trigger",
|
||||
event: "cron:trigger",
|
||||
icon: "ri-timer-line",
|
||||
tagline: "Cron Trigger - {{inputs.cron}}",
|
||||
tagline: "Cron Trigger (<b>{{inputs.cron}}</b>)",
|
||||
description: "Triggers automation on a cron schedule.",
|
||||
stepId: "CRON",
|
||||
inputs: {},
|
||||
|
@ -211,7 +211,7 @@ const BUILTIN_DEFINITIONS = {
|
|||
cron: {
|
||||
type: "string",
|
||||
customType: "cron",
|
||||
title: "Cron Expression",
|
||||
title: "Expression",
|
||||
},
|
||||
},
|
||||
required: ["cron"],
|
||||
|
|
Loading…
Reference in New Issue