Skip to content

Commit 20164da

Browse files
author
Ayush Jha
committed
feat: add jobs section to app.yaml configuration docs
1 parent 0163c2d commit 20164da

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed

pages/edge/configuration.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,8 @@ scaling:
307307
```
308308

309309
- Required: `false`
310+
311+
312+
### `jobs`
313+
314+
This section is defined on [jobs](/edge/configuration/jobs) page.

pages/edge/configuration/jobs.mdx

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Jobs
2+
3+
## Introduction
4+
5+
The `jobs` section allows defining scheduled or event-driven tasks
6+
that execute commands or make HTTP requests. Jobs can be useful for
7+
running periodic maintenance tasks, executing background processes, or
8+
ensuring essential workflows are automated.
9+
10+
11+
## Job Structure
12+
13+
Each job consists of the following fields:
14+
15+
- **name** *(str, required)* – A unique name for the job.
16+
- **trigger** *(str, required)* – Defines when the job should run.
17+
- This can be a cron expression (e.g., `'*/15 * * * *'` for every 15
18+
minutes).
19+
- It can also be `'post-deployment'` to run after deployment.
20+
- `'pre-deployment'` is currently not supported.
21+
- **action** *(required)* – Specifies the task to run. More details
22+
in the [next section](#job-actions). A job can:
23+
- Run a command using `execute`.
24+
- Make an HTTP request using `fetch`.
25+
- **retries** *(int, Optional)* – The maximum number of times the job
26+
should retry upon failure.
27+
- **timeout** *(duration, Optional)* – The maximum time a job is
28+
allowed to run before timing out (e.g., `'10m'` for 10 minutes).
29+
- **max_schedule_drift** *(Optional[PrettyDuration])* – The maximum
30+
allowed delay before the job is considered late.
31+
32+
33+
Fully working examples configuration can be found
34+
[here](#example-jobs-configuration).
35+
36+
37+
## Job Actions
38+
39+
This section defines the `action` field in a job definition. There are
40+
two types of actions for a job:
41+
42+
1. **Executing a command (`execute`)**
43+
44+
Runs a CLI command with Optional environment variables.
45+
```yaml
46+
action:
47+
execute:
48+
command: install-wp
49+
cli_args:
50+
- "--version"
51+
- "--help"
52+
env:
53+
LOG_LEVEL: DEBUG
54+
EXTRA_FLAGS: "--enable-feature-1 --enable-feature-2"
55+
```
56+
- `command` *(str, Optional)* – The command to execute.
57+
- `cli_args` *(List[str], Optional)* – Arguments for the command.
58+
- `env` *(map, Optional)* – Environment variables.
59+
60+
2. **Making an HTTP request (`fetch`)**
61+
62+
Sends an HTTP request to a specific endpoint.
63+
```yaml
64+
action:
65+
fetch:
66+
path: /wp-cron.php
67+
timeout: '10m'
68+
headers:
69+
- name: Accept
70+
value: application/json
71+
- name: User-Agent
72+
value: Wasmer-CronJob
73+
74+
```
75+
- `path` *(str, required)* – The request URL path.
76+
- `method` *(str, Optional)* – HTTP method (defaults to `GET`).
77+
- `headers` *(map, Optional)* – HTTP headers.
78+
- `body` *(str, Optional)* – Request body.
79+
- `timeout` *(duration, Optional)* – Maximum time to wait for
80+
a response.
81+
82+
## Example Jobs Configuration
83+
84+
Below are examples of various job types based on their trigger and
85+
action.
86+
87+
88+
### Fetch job
89+
90+
This job fetches the `/` path on it's app every 15 minutes.
91+
```yaml
92+
kind: wasmer.io/App.v0
93+
package: wasmer/hello
94+
jobs:
95+
- name: ping-server-every-15-minutes
96+
trigger: '*/15 * * * *'
97+
action:
98+
fetch:
99+
path: /
100+
timeout: 30s
101+
```
102+
103+
104+
### Execute job
105+
106+
This job runs `php --version` every minute.
107+
108+
```yaml
109+
kind: wasmer.io/App.v0
110+
package: wasmer/wordpress
111+
jobs:
112+
- name: check-php-version
113+
trigger: '*/1 * * * *'
114+
execute:
115+
command: php
116+
cli_args: ["--version"]
117+
```
118+
119+
### Post deployment job
120+
121+
This job fetches the `/warm-up-caches` path on it's app after
122+
each deployment.
123+
124+
```yaml
125+
kind: wasmer.io/App.v0
126+
package: wasmer/hello
127+
jobs:
128+
- name: ping-server-every-15-minutes
129+
trigger: post-deployment
130+
action:
131+
fetch:
132+
path: /warm-up-caches
133+
timeout: 30s
134+
```
135+
136+
137+
## Use Cases
138+
139+
- **Post-deployment setup:** The `installation` job ensures necessary
140+
setup commands run after deployment.
141+
- **Scheduled background tasks:** The `wp-cron` job triggers
142+
WordPress’s cron system every 15 minutes.

0 commit comments

Comments
 (0)