Schedule based trigger
This is a scheduled task that runs automatically at predefined intervals.
Tutorial steps
To create a schedule based trigger, you'll need to:
- Activate the Executor service
- Add the trigger in
executor.cue
manifest file - Apply the change using
tailorctl
1. Activate the Executor service
To activate the Executor service, add executor
service to the list of services in the workspace.cue
file as the following.
<span><span style="color: var(--shiki-token-keyword)">package</span><span style="color: var(--shiki-color-text)"> v2</span></span>
<span></span>
<span><span style="color: var(--shiki-token-keyword)">import</span><span style="color: var(--shiki-color-text)"> (</span></span>
<span><span style="color: var(--shiki-color-text)"> ...</span></span>
<span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-color-text)">"</span><span style="color: var(--shiki-token-string-expression)">tailor.build/template/services/executor</span><span style="color: var(--shiki-color-text)">"</span></span>
<span><span style="color: var(--shiki-color-text)">)</span></span>
<span></span>
<span><span style="color: var(--shiki-color-text)">v2.#Workspace </span><span style="color: var(--shiki-token-keyword)">&</span><span style="color: var(--shiki-color-text)"> {</span></span>
<span><span style="color: var(--shiki-color-text)"> Apps: [</span></span>
<span><span style="color: var(--shiki-color-text)"> application</span></span>
<span><span style="color: var(--shiki-color-text)"> ]</span></span>
<span><span style="color: var(--shiki-color-text)"> Services: [tailordb</span><span style="color: var(--shiki-token-punctuation)">,</span><span style="color: var(--shiki-color-text)"> pipeline</span><span style="color: var(--shiki-token-punctuation)">,</span><span style="color: var(--shiki-color-text)"> auth</span><span style="color: var(--shiki-token-punctuation)">,</span><span style="color: var(--shiki-color-text)"> executor]</span></span>
<span><span style="color: var(--shiki-color-text)">}</span></span>
<span></span>
2. Add the trigger in executor.cue
manifest file
package executor
import (
"github.com/tailor-platform/tailorctl/schema/v2/executor"
)
executor.#Spec & {
Executors: [
#triggerSchedule,
]
}
#triggerSchedule: executor.#Executor & {
Name: "name"
Description: "description"
Trigger: executor.#TriggerSchedule & {
Timezone: "UTC"
Frequency: "* * * * *"
}
Target: executor.#TargetWebhook & {
URL: "http://localhost"
Body: common.#Script & {
Expr: """
({
"key": value
})"""
}
}
}
3. Apply the change using tailorctl
Run the following command to apply the changes.
<span></span>
<span><span style="color: var(--shiki-token-comment)"># Apply Executor</span></span>
<span><span style="color: var(--shiki-token-function)">tailorctl</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string)">workspace</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string)">apply</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string)">-m</span><span style="color: var(--shiki-color-text)"> </span><span style="color: var(--shiki-token-string)">./workspace.cue</span></span>
<span></span>