Schedule Configuration

Configure scheduled command execution using cron expressions

Schedule Configuration

Defines a scheduled task that executes a command with arguments at specified times using Quartz cron expressions. When created, Weik.io automatically generates an Apache Camel integration flow for execution.

Schema Properties

PropertyTypeRequiredDefaultDescription
cronstringYes-Quartz cron expression (6 fields: seconds minutes hours day-of-month month day-of-week)
commandstringYes-Command to execute
argsstring[]No[]Command-line arguments passed to the command
requirementsDictionary<string, string>No{}Key-value pairs for Integration Agent selection

YAML Examples

Basic Schedule

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://webhook.site/ba5c0205-78e6-49d6-b80c-5a6da03ffcc0?hello=schedule"
  requirements:
    Environment: production
    Network: external

Run Python Script

apiVersion: weik.io/v1alpha1
kind: Schedule
metadata:
  name: data-sync
  description: Sync data every hour
spec:
  cron: "0 0 0/1 * * ?"
  command: python
  args:
    - "/opt/scripts/sync-data.py"
    - "--incremental"
  requirements:
    Environment: production
    Region: us-west

Execute Shell Script Daily

apiVersion: weik.io/v1alpha1
kind: Schedule
metadata:
  name: nightly-backup
  description: Backup database at 2 AM
spec:
  cron: "0 0 2 * * ?"
  command: bash
  args:
    - "/scripts/backup-database.sh"
  requirements:
    Environment: production
    DatabaseAccess: "true"

Multiple Schedules

apiVersion: weik.io/v1alpha1
kind: Schedule
metadata:
  name: health-check
spec:
  cron: "0 0/5 * * * ?"
  command: curl
  args:
    - "-f"
    - "https://api.example.com/health"
  requirements:
    Environment: production
    Network: external
---
apiVersion: weik.io/v1alpha1
kind: Schedule
metadata:
  name: weekly-report
spec:
  cron: "0 0 9 ? * MON"
  command: python
  args:
    - "/scripts/generate-report.py"
    - "--type"
    - "weekly"
  requirements:
    Environment: production
    Team: reporting
---
apiVersion: weik.io/v1alpha1
kind: Schedule
metadata:
  name: cleanup-temp
spec:
  cron: "0 0 3 * * ?"
  command: bash
  args:
    - "/scripts/cleanup.sh"
    - "--days"
    - "30"
  requirements:
    Environment: production
    OS: linux

Complex Command with Multiple Arguments

apiVersion: weik.io/v1alpha1
kind: Schedule
metadata:
  name: api-call-with-auth
  description: Call API with authentication
spec:
  cron: "0 0 8 * * MON-FRI"
  command: curl
  args:
    - "-X"
    - "POST"
    - "https://api.example.com/sync"
    - "-H"
    - "Authorization: Bearer ${API_TOKEN}"
    - "-H"
    - "Content-Type: application/json"
    - "-d"
    - '{"action":"sync","timestamp":"${TIMESTAMP}"}'
  requirements:
    Environment: production
    Network: external
    Team: integration

Cron Expression Format

Schedules use Quartz cron syntax with 6 fields:

seconds minutes hours day-of-month month day-of-week
   0       0       2        *         *        ?

│ │ │ │ │ │
│ │ │ │ │ └─ Day of week (1-7 or MON-SUN, ? for no specific value)
│ │ │ │ └─── Month (1-12 or JAN-DEC)
│ │ │ └───── Day of month (1-31, ? for no specific value)
│ │ └─────── Hour (0-23)
│ └───────── Minute (0-59)
└─────────── Second (0-59)

Common Cron Patterns

PatternDescription
0 0/1 * * * ?Every minute at 0 seconds
0 0/5 * * * ?Every 5 minutes
0 0 0/1 * * ?Every hour
0 0 2 * * ?Daily at 2:00 AM
0 0 9 ? * MON-FRIWeekdays at 9:00 AM
0 0 0 1 * ?First day of month at midnight
0 0 9 ? * MONEvery Monday at 9:00 AM
0 0/15 * * * ?Every 15 minutes

Special Characters

  • * - Any value (all values for that field)
  • ? - No specific value (use in day-of-month or day-of-week)
  • - - Range of values (e.g., MON-FRI)
  • , - List of values (e.g., MON,WED,FRI)
  • / - Increments (e.g., 0/15 for every 15 seconds/minutes/etc.)

Usage Notes

Command Execution

The command field specifies the executable to run. The command must be available on the Integration Agent:

  • curl - Make HTTP requests
  • python - Execute Python scripts
  • node - Run Node.js scripts
  • bash - Execute shell scripts
  • Any system command available to the agent

Arguments

The args array passes arguments to the command in order:

args:
  - "-X"
  - "POST"
  - "https://api.example.com"
  - "-H"
  - "Content-Type: application/json"

Arguments are passed directly to the command as separate values. Quote arguments with spaces in your shell but not in the YAML array.

Requirements for Agent Selection

Requirements are key-value pairs used to select which Integration Agent executes the schedule. Requirements specify agent capabilities and selection criteria, NOT package names or versions.

How Requirements Work:

  1. Integration Agents register with specific capabilities
  2. Schedules specify requirements
  3. Weik.io matches schedules to agents with compatible capabilities
  4. Only matching agents execute the schedule

Example Requirements:

requirements:
  Environment: production
  Region: eu-west
  Datacenter: dc1
  DatabaseAccess: postgres
  Network: external

Common Requirement Keys:

  • Environment - Deployment environment (production, staging, dev)
  • Region - Geographic region or cloud region
  • Datacenter - Specific datacenter or availability zone
  • Network - Network access type (internal, external, vpn)
  • DatabaseAccess - Database connectivity requirements
  • OS - Operating system (linux, windows, macos)
  • Team - Team ownership or access
  • Custom keys - Any agent-specific capability

Generated Integration Flow

When you create a Schedule, Weik.io generates an Apache Camel integration flow:

- from:
    uri: "quartz:{{schedule.name}}"
    parameters:
      cron: "{{schedule.cron}}"
    steps:
      - to:
          uri: exec
          parameters:
            executable: "{{schedule.command}}"
            args: "{{schedule.args}}"

The flow:

  • Uses Quartz for cron-based scheduling
  • Executes commands via Apache Camel’s exec component
  • Passes arguments to the command
  • Creates a NATS stream for the schedule
  • Runs on agents with matching requirements

Execution Behavior

  • Schedules trigger based on the cron expression
  • Commands execute on Integration Agents with matching requirements
  • If no agent matches requirements, the schedule will not execute
  • Failed executions do not retry automatically (implement retry logic in your script)
  • Schedules continue after failures (one failure doesn’t stop future runs)

Error Handling

Implement error handling in your commands and scripts:

Bash Script:

#!/bin/bash
set -e  # Exit on error

if ! command -v curl &> /dev/null; then
    echo "curl is not installed"
    exit 1
fi

curl -f "https://api.example.com" || {
    echo "API call failed"
    exit 1
}

Python Script:

import sys
import logging

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

try:
    # Your task logic
    result = perform_task()
    logger.info(f"Task completed: {result}")
except Exception as e:
    logger.error(f"Task failed: {e}", exc_info=True)
    sys.exit(1)

Best Practices

Use 6-Field Cron Format Always use Quartz format with seconds:

cron: "0 0 2 * * ?"  # Correct: 6 fields

Test Commands Manually Before scheduling, verify the command works on an agent:

curl -X GET https://api.example.com/health
python /opt/scripts/sync-data.py --incremental

Specify Clear Requirements Make requirements specific and meaningful:

requirements:
  Environment: production
  Region: us-east
  Datacenter: az1

Use Descriptive Names

metadata:
  name: nightly-database-backup
  description: Backup PostgreSQL to S3 daily at 2 AM

Avoid Overlapping Executions Choose cron intervals longer than typical execution time to prevent overlap.

Monitor and Log Implement logging in scripts to track execution and debug failures.

Handle Missing Agents Ensure at least one agent with matching requirements is running before deploying a schedule.

Quote Special Characters Use single quotes for JSON or complex strings in args:

args:
  - "-d"
  - '{"key":"value","timestamp":"${NOW}"}'

Limitations

The Schedule configuration:

  • Does not support timezone specification (uses agent timezone)
  • Does not provide built-in retry logic (implement in your script)
  • Does not prevent concurrent executions (design commands to handle this)
  • Requires matching Integration Agent to execute

Schedules work with:

  • IntegrationFlow - Generated automatically for each schedule
  • Variable - Use variables in command arguments
  • Integration Agents - Execute scheduled commands

See Also