Scheduled Tasks
Stash can execute scheduled tasks in the background, currently only supporting JavaScript scripts. Scheduled tasks require Network Extension (VPN) to be connected.
Script / Scheduled Script
Stash can execute JavaScript scripts in the background on a schedule to automate tasks. The results of the execution can be notified through system notifications or recorded in persistent storage.
Please refer to Syntax and Interface for the syntax and interface of JavaScript scripts.
Configuration Structure
Scheduled scripts are configured under cron.script, with script sources declared through script-providers:
cron:
script:
- name: your-script-name
cron: '*/5 * * * *' # Execution schedule expression
argument: '{ "key": true }' # Optional, runtime parameter
timeout: 10 # Optional, timeout in seconds, defaults to 30
engine: auto # Optional, script execution engine
script-providers:
your-script-name:
url: https://example.com/your-script.js
interval: 86400Engine Selection and Cron Expression Enhancements
BetaiOS/tvOS5.1+macOS5.1+Script Engine (engine)
cron.script supports specifying the JavaScript engine used to run scheduled tasks via the engine field:
auto: Default; automatically selects an available engine.webkit: Executes using the WebKit engine.jsc: Executes using the JavaScriptCore engine.
Cron Expression Syntax
Scheduled scripts support both 5-field and 6-field Cron expressions:
- 6-field format:
second minute hour day month weekday(seconds first). - 5-field format:
minute hour day month weekday, with seconds fixed to0.
Enhanced syntax features include:
- Operators: Supports
*(any value),,(value list),-(range), and/(step). - English abbreviations: Case-insensitive abbreviations are supported for months (
JAN-DEC) and weekdays (SUN-SAT). - Question mark placeholder: Both day-of-month and weekday fields support
?as the entire field value, equivalent to*. - Sunday representation: The weekday field supports both
7and0for Sunday.
cron:
script:
# 6-field expression: runs Monday to Friday at 09:30:00 using the jsc engine
- name: workday-task
cron: '0 30 9 ? * MON-FRI'
engine: jsc
# Runs every 30 seconds
- name: frequent-sync
cron: '*/30 * * * * *'
engine: webkit
# 5-field expression: runs at 20:00 on the 1st and 15th of each month
- name: biweekly-report
cron: '0 20 1,15 * *'You can reference the same script in multiple scenarios and determine the event source (such as HTTP rewriting, scheduled tasks, or event scripts) through environment variables.