1
0
Fork 0
mirror of synced 2024-07-03 05:20:32 +12:00

Adding cron presets to automations

This commit is contained in:
Martin McKeaveney 2021-05-18 22:20:41 +01:00
parent c3dc5bae76
commit a781239632
4 changed files with 60 additions and 5 deletions

View file

@ -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"}

View file

@ -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>

View file

@ -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 } }

View file

@ -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"],