Skip to main content
Version: 4.x

Scheduled Tasks

Overview

Scheduled tasks maintain recurring jobs. For example, an ordering application needs unpaid orders to be closed after a timeout; a task that calls an endpoint of the application every minute takes care of that. Tasks run on one or more hosts or on the Spug server itself, as Shell or Python scripts.

Scheduled tasks

New task

Creating a task takes three steps: Create task → Set trigger → Select targets.

1. Create task

Create task

  • Task type: a category; new categories can be typed into the drop-down.
  • Task name: the name.
  • Content: the script, Shell or Python; Add from template reuses batch execution templates.
  • Failure notification: notify on failure via DingTalk, Feishu, WeCom bots or a custom Webhook.
  • Description: optional.

2. Set trigger

Set trigger

TriggerDescription
Intervalrun every N seconds
One-offrun once at the given time
UNIX croncrontab-style rule, e.g. 0 1 * * * for 01:00 every day; 1-5, 2-5/2 and 1,3,5 are supported and the next run times are previewed; an optional start and end time limit the active period
Monitor alertrun when the selected monitors raise an alert, for self-healing such as restarting a service after a process check fails

3. Select targets

Select targets

  • Targets: one or more hosts, or Local (the container or server running Spug).
  • With the Monitor alert trigger you can also choose Alerting host, i.e. the host that raised the alert (only process and custom script monitors have an associated host).

Managing tasks

  • New tasks are inactive; use Activate Task in the More menu to start scheduling and Disable Task to stop it; the menu also offers Run Test, History and Delete.
  • More / Run test executes the task once on its targets for debugging.
  • Details shows the execution history with status, duration and output of every run plus success / failure counts and the average duration.

Execution history

Only the most recent 50 records of a task are kept; older ones are removed automatically.

Notes

  • Scheduled tasks depend on the runscheduler and runworker services; the Docker install includes them, for manual deployments see Development FAQ.
  • Scheduled task scripts do not receive the SPUG_* host variables of batch execution; obtain host information inside the script (for example with hostname -I) if you need it.
  • Tasks run in a non-interactive shell; for command not found errors see Best practices.