Scheduled Tasks
Execute commands on a schedule using cron expressions
Scheduled Tasks run commands automatically at specified times using standard cron expressions.
When you create a Schedule, Weik.io generates an Apache Camel integration flow. This flow uses Quartz to handle the timing and the Camel exec component to run your command.
How it works
You do not need to configure Camel or Quartz manually. When you write a Schedule configuration:
- Weik.io saves your cron expression, command, and arguments.
- It automatically generates the Camel integration flow.
- It creates a NATS stream for the schedule.
- Quartz triggers the flow when the cron expression matches.
- An Integration Agent with matching requirements picks up the job and runs the command.
Writing a Schedule
You define schedules using a YAML configuration file.
apiVersion: weik.io/v1alpha1
kind: Schedule
metadata:
name: webhook-test
description: Call webhook every minute
spec:
cron: "0 0/1 * * * ?"
command: curl
args:
- "-X"
- GET
- "https://api.example.com/health"
requirements:
Environment: production
Network: external
The spec
cron(required): A 6-field Quartz cron expression.command(required): The executable to run. This can becurl,python,node,bash, or any other binary installed on the target Integration Agent.args(optional): A list of command-line arguments. These are passed exactly as you write them, in order.requirements(optional): Key-value pairs that determine where this command runs.
Targeting specific agents
Use requirements to route the schedule to the correct Integration Agent. For example, this ensures a database backup script runs only on a node with database access.
If your schedule looks like this:
requirements:
Environment: production
Datacenter: eu-west
DatabaseAccess: "true"
It only executes on an Integration Agent that started with those exact capabilities. If no agent matches, the schedule does not run.
Cron expression format
Schedules use Quartz cron syntax. This requires 6 fields (seconds are included), which is different from standard Linux cron (5 fields).
* * * * * *
│ │ │ │ │ │
│ │ │ │ │ └─ Day of week (1-7 or MON-SUN)
│ │ │ │ └─── Month (1-12 or JAN-DEC)
│ │ │ └───── Day of month (1-31)
│ │ └─────── Hour (0-23)
│ └───────── Minute (0-59)
└─────────── Second (0-59)
Common patterns:
0 0/5 * * * ?- Every 5 minutes, at exactly 0 seconds0 0 0/1 * * ?- Top of every hour0 0 2 * * ?- Daily at 2:00:00 AM0 0 9 ? * MON-FRI- Weekdays at 9 AM
Examples
Nightly database backup
apiVersion: weik.io/v1alpha1
kind: Schedule
metadata:
name: nightly-backup
spec:
cron: "0 0 2 * * ?"
command: bash
args:
- "/scripts/backup-database.sh"
requirements:
Environment: production
DatabaseAccess: "true"
Run a Python sync script
apiVersion: weik.io/v1alpha1
kind: Schedule
metadata:
name: data-sync
spec:
cron: "0 0 0/1 * * ?"
command: python
args:
- "/opt/scripts/sync-data.py"
- "--incremental"
requirements:
Environment: staging
Trigger an API report
apiVersion: weik.io/v1alpha1
kind: Schedule
metadata:
name: trigger-report
spec:
cron: "0 0 8 * * MON-FRI"
command: curl
args:
- "-X"
- "POST"
- "https://api.example.com/reports/generate"
- "-H"
- "Authorization: Bearer ${API_TOKEN}"
- "-H"
- "Content-Type: application/json"
- "-d"
- '{"reportType":"daily","format":"pdf"}'
Troubleshooting
If a schedule does not behave as expected, check the following:
The schedule never runs Make sure the cron expression has exactly 6 fields. Standard crontab generators usually output 5 fields, which fails because Quartz requires the seconds field. Also verify that an agent matching your requirements is online.
The command fails immediately The agent executing the schedule must have the executable installed. If you schedule a python script, the agent needs Python in its PATH. Test the command manually on the target machine first.
Arguments are ignored or malformed Check the YAML args array. Do not write -X POST as a single argument. It must be two separate list items:
args:
- "-X"
- "POST"
Overlapping executions If a script takes 10 minutes to run, do not schedule it every 5 minutes. The system starts a second instance while the first is still running, which can cause file locks or database deadlocks.
Next steps
- Automation Overview - Learn about automation features
- Integration Flows - Understand integration flows
- Schedule Configuration Reference - Complete configuration schema