Jobs
Introduction
The jobs section allows defining scheduled or event-driven tasks
that execute commands or make HTTP requests. Jobs can be useful for
running periodic maintenance tasks, executing background processes, or
ensuring essential workflows are automated.
Job Structure
Each job consists of the following fields:
- name (str, required) – A unique name for the job.
- trigger (str, required) – Defines when the job should run.
- Use a duration such as
15m,1h, or24hfor simple interval schedules. - Use a cron expression for uniform schedules, such as
'*/15 * * * *'for every 15 minutes. - Use
pre-deploymentto run before a new app version is created. - Use
post-deploymentto run after a new app version is created.
- Use a duration such as
- action (required) – Specifies the task to run. More details
in the next section. A job can:
- Run a command using
execute. - Make an HTTP request using
fetch.
- Run a command using
Fully working examples configuration can be found here.
Schedules and Deployment Triggers
Scheduled jobs can use either a duration or a cron expression. Cron expressions
must produce a uniform interval. For example, */15 * * * * is valid because it
runs every 15 minutes, while a schedule such as 0 9 * * MON-FRI is not uniform
because the interval between Friday and Monday is different.
Scheduled jobs are subject to the platform minimum interval, which defaults to 5
minutes. Deployment jobs use the special pre-deployment and post-deployment
triggers and run once during deployment instead of being installed as recurring
cron jobs.
Job Actions
This section defines the action field in a job definition. There are
two types of actions for a job:
-
Executing a command (
execute)Runs a CLI command with Optional environment variables.
action: execute: command: install-wp cli_args: - "--version" - "--help" env: LOG_LEVEL: DEBUG EXTRA_FLAGS: "--enable-feature-1 --enable-feature-2"command(str, Optional) – The command to execute. If omitted, the app workload command is used.package(str, Optional) – Package source override for this job.cli_args(List[str], Optional) – Arguments for the command.env(map[str, str], Optional) – Environment variables.retries(int, Optional) – Maximum retry count.timeout(duration, Optional) – Maximum runtime. Defaults to180s.max_schedule_drift(duration, Optional) – Maximum allowed delay before a scheduled job is considered late. Defaults to180s.
-
Making an HTTP request (
fetch)Sends an HTTP request to a specific endpoint.
action: fetch: path: /wp-cron.php timeout: '10m' headers: - name: Accept value: application/json - name: User-Agent value: Wasmer-CronJob expect: status_codes: [200, 204]path(str, Optional) – The request URL path. Defaults to/.method(str, Optional) – HTTP method. Defaults toGET.headers(List[Header], Optional) – HTTP headers passed as a list ofname/valuepairs.body(str, Optional) – Request body.expect.status_codes(List[int], Optional) – Expected HTTP status codes.expect.body_includes(str, Optional) – Text that must be present in the response body.expect.body_regex(str, Optional) – Regular expression that must match the response body.retries(int, Optional) – Maximum retry count.timeout(duration, Optional) – Maximum time to wait for a response. Defaults to180s.max_schedule_drift(duration, Optional) – Maximum allowed delay before a scheduled job is considered late. Defaults to180s.
Example Jobs Configuration
Below are examples of various job types based on their trigger and action.
Fetch job
This job fetches the / path on its app every 15 minutes.
kind: wasmer.io/App.v0
package: wasmer/static-web-server
jobs:
- name: ping-server-every-15-minutes
trigger: '*/15 * * * *'
action:
fetch:
path: /
timeout: 30s
headers:
- name: User-Agent
value: Wasmer-CronJobInterval job
This job runs on a simple duration schedule.
kind: wasmer.io/App.v0
package: wasmer/static-web-server
jobs:
- name: ping-server-every-hour
trigger: 1h
action:
fetch:
path: /
timeout: 30sExecute job
This job runs a shell command every 15 minutes and writes the output to the
job logs. Use execute when a cron job should run a package command instead of
making an HTTP request.
kind: wasmer.io/App.v0
package: wasmer/bash
jobs:
- name: write-heartbeat
trigger: '*/15 * * * *'
action:
execute:
command: bash
cli_args: ["-lc", "date -u && echo cron heartbeat"]Pre deployment job
This job runs a setup command before a new app version is created.
kind: wasmer.io/App.v0
package: wasmer/static-web-server
jobs:
- name: prepare-release
trigger: pre-deployment
action:
execute:
package: wasmer/bash
command: bash
cli_args: ["-lc", "echo preparing release"]
timeout: 5mPost deployment job
This job fetches the / path on its app after each deployment.
kind: wasmer.io/App.v0
package: wasmer/static-web-server
jobs:
- name: warm-up-app
trigger: post-deployment
action:
fetch:
path: /
timeout: 30sUse Cases
- Pre-deployment migrations: Run setup or migration commands before publishing the new version.
- Post-deployment setup: The
installationjob ensures necessary setup commands run after deployment. - Scheduled background tasks: The
wp-cronjob triggers WordPress’s cron system every 15 minutes.