Skip to content

Commit 1f52448

Browse files
committed
feat: add docs for cron job feature in paas native
1 parent 54d8ce9 commit 1f52448

File tree

1 file changed

+263
-0
lines changed

1 file changed

+263
-0
lines changed
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
---
2+
nav:
3+
title: Manage Cron Jobs
4+
position: 80
5+
---
6+
7+
# Manage Cron Jobs
8+
9+
Cron Jobs let you schedule recurring tasks for your application, such as cache warming, search index updates, or data exports. They are defined in your `application.yaml` and managed via the PaaS CLI.
10+
11+
::: info
12+
The PaaS native cron job feature does **not** replace Shopware's built-in Scheduled Tasks. It is an addition to them and does not interact with the Scheduled Task system in any way.
13+
:::
14+
15+
## Defining Cron Jobs in application.yaml
16+
17+
Cron Jobs are declared under the `cronJobs` key in your `application.yaml`. They are automatically created, updated, or removed whenever you deploy a new version of your configuration.
18+
19+
::: warning
20+
Cron Jobs are **disabled by default**. After deploying, you must explicitly enable them via the CLI before they will run. See [Enable or disable Cron Jobs](#enable-or-disable-cron-jobs).
21+
:::
22+
23+
```yaml
24+
app:
25+
php:
26+
version: "8.3"
27+
environment_variables: []
28+
services:
29+
mysql:
30+
version: "8.0"
31+
opensearch:
32+
enabled: false
33+
cronJobs:
34+
- name: reindex-elasticsearch
35+
schedule: "0 3 * * *"
36+
command: "bin/console es:index"
37+
38+
- name: warmup-cache
39+
schedule: "*/30 * * * *"
40+
command: "bin/console cache:warmup"
41+
```
42+
43+
### Field Reference
44+
45+
| Field | Required | Default | Description |
46+
|---|---|---|---|
47+
| `name` | Yes | — | Unique identifier for this cron job |
48+
| `schedule` | Yes | — | Cron expression (5-field standard format) |
49+
| `command` | Yes | — | Shell command to run |
50+
| `timezone` | No | `UTC` | IANA timezone for the schedule |
51+
52+
### Name Format
53+
54+
The `name` field must follow these rules:
55+
56+
- Only **lowercase** letters (`a-z`), digits (`0-9`), and hyphens (`-`)
57+
- Must **start and end** with a letter or digit (not a hyphen)
58+
- Minimum length of 2 characters
59+
60+
**Valid examples:** `reindex-elasticsearch`, `daily-cleanup`, `warmup-cache`
61+
**Invalid examples:** `My-Job` (uppercase), `-my-job` (starts with hyphen), `my_job` (underscore)
62+
63+
### Schedule Format
64+
65+
The `schedule` field uses the standard 5-field cron format:
66+
67+
```
68+
┌─────────── minute (0–59)
69+
│ ┌───────── hour (0–23)
70+
│ │ ┌─────── day of month (1–31)
71+
│ │ │ ┌───── month (1–12)
72+
│ │ │ │ ┌─── day of week (0–6, Sunday = 0)
73+
│ │ │ │ │
74+
* * * * *
75+
```
76+
77+
**Common examples:**
78+
79+
| Schedule | Description |
80+
|---|---|
81+
| `0 3 * * *` | Every day at 03:00 |
82+
| `*/15 * * * *` | Every 15 minutes |
83+
| `0 0 * * 0` | Every Sunday at midnight |
84+
| `30 8 1 * *` | First day of the month at 08:30 |
85+
86+
### Timezones
87+
88+
By default, all schedules run in **UTC**. Use the `timezone` field to run a job in a different timezone. Any [IANA timezone](https://www.iana.org/time-zones) identifier is valid.
89+
90+
```yaml
91+
cronJobs:
92+
- name: midnight-report
93+
schedule: "0 0 * * *"
94+
command: "bin/console report:generate"
95+
# Runs at midnight Berlin time
96+
timezone: Europe/Berlin
97+
```
98+
99+
::: warning
100+
The value `Local` is explicitly not allowed as a timezone. Always use a specific IANA identifier such as `Europe/Berlin` or `America/New_York`.
101+
:::
102+
103+
## Managing Cron Jobs via the CLI
104+
105+
### List all Cron Jobs
106+
107+
```bash
108+
sw-paas application cronjob list
109+
```
110+
111+
This shows all cron jobs for your application with their current status:
112+
113+
```
114+
┌──────────────────────┬───────────────────────┬─────────────────┬──────────────────────┬──────────┬─────────┬──────────────────────┬───────────┐
115+
│ Id │ Name │ Schedule │ Command │ Timezone │ Enabled │ Last Run │ Last ... │
116+
├──────────────────────┼───────────────────────┼─────────────────┼──────────────────────┼──────────┼─────────┼──────────────────────┼───────────┤
117+
│ 8fc7d8a3-... │ reindex-elasticsearch │ 0 3 * * * │ bin/console es:index │ UTC │ true │ 2024-03-12 03:00:00 │ SUCCEEDED │
118+
│ 2b9e6f1d-... │ warmup-cache │ */30 * * * * │ bin/console cache:.. │ UTC │ false │ 2024-03-11 14:30:00 │ FAILED │
119+
└──────────────────────┴───────────────────────┴─────────────────┴──────────────────────┴──────────┴─────────┴──────────────────────┴───────────┘
120+
```
121+
122+
To output as JSON:
123+
124+
```bash
125+
sw-paas application cronjob list -o json
126+
```
127+
128+
### Get details of a single Cron Job
129+
130+
```bash
131+
sw-paas application cronjob get --id <cronjob-id>
132+
```
133+
134+
If you omit `--id`, the CLI opens an interactive selection prompt.
135+
136+
```
137+
┌─────────────┬──────────────────────────┐
138+
│ Property │ Value │
139+
├─────────────┼──────────────────────────┤
140+
│ ID │ 8fc7d8a3-... │
141+
│ Name │ reindex-elasticsearch │
142+
│ Schedule │ 0 3 * * * │
143+
│ Command │ bin/console es:index
144+
│ Timezone │ UTC │
145+
│ Enabled │ true │
146+
│ Last Run │ 2024-03-12 03:00:00 │
147+
│ Last Status │ SUCCEEDED │
148+
└─────────────┴──────────────────────────┘
149+
```
150+
151+
### Enable or disable Cron Jobs
152+
153+
After making changes to the enabled state of a Cron Job via the CLI, a new deployment is required for the change to take effect.
154+
155+
::: warning
156+
Changes made with `cronjob update` are only applied after a new deployment of your application. Without redeploying, the scheduler will continue to use the previous state.
157+
:::
158+
159+
**Interactive mode** — toggle any job via a menu:
160+
161+
```bash
162+
sw-paas application cronjob update
163+
```
164+
165+
Controls: `↑/↓` navigate · `space` toggle · `a` enable all · `d` disable all · `enter` confirm · `q` / `esc` abort
166+
167+
**Enable or disable a specific job:**
168+
169+
```bash
170+
sw-paas application cronjob update --id <cronjob-id> --enable
171+
sw-paas application cronjob update --id <cronjob-id> --disable
172+
```
173+
174+
**Enable or disable all jobs at once:**
175+
176+
```bash
177+
sw-paas application cronjob update --enable --all
178+
sw-paas application cronjob update --disable --all
179+
```
180+
181+
::: info
182+
`--enable` and `--disable` are mutually exclusive. `--all` and `--id` are mutually exclusive.
183+
:::
184+
185+
### View execution history
186+
187+
The history shows every execution run with its status and timestamps. History is retained for **61 days**.
188+
189+
```bash
190+
sw-paas application cronjob history list
191+
```
192+
193+
**Filter by date or time range:**
194+
195+
```bash
196+
# All runs on a specific day
197+
sw-paas application cronjob history list --date 2024-01-15
198+
199+
# Runs within a time range
200+
sw-paas application cronjob history list --from "2024-01-15 08:00" --to "2024-01-15 18:00"
201+
```
202+
203+
**Filter by job or run:**
204+
205+
```bash
206+
# History for a specific cron job
207+
sw-paas application cronjob history list --cronjob-id <cronjob-id>
208+
209+
# Details for a specific run
210+
sw-paas application cronjob history list --run-id <run-id>
211+
```
212+
213+
**Pagination:**
214+
215+
```bash
216+
sw-paas application cronjob history list --limit 100 --offset 50
217+
```
218+
219+
::: info
220+
`--date` cannot be combined with `--from` or `--to`.
221+
:::
222+
223+
**Example output:**
224+
225+
```
226+
┌────────────────┬───────────┬─────────────────────┬──────────┐
227+
│ Run ID │ Status │ Timestamp │ Timezone │
228+
├────────────────┼───────────┼─────────────────────┼──────────┤
229+
│ run-abc123 │ RUNNING │ 2024-03-12 03:00:00 │ UTC │
230+
│ │ SUCCEEDED │ 2024-03-12 03:00:45 │ UTC │
231+
│ │ │ │ │
232+
│ run-def456 │ RUNNING │ 2024-03-11 03:00:00 │ UTC │
233+
│ │ FAILED │ 2024-03-11 03:00:10 │ UTC │
234+
└────────────────┴───────────┴─────────────────────┴──────────┘
235+
```
236+
237+
### Logs
238+
239+
The full output of each Cron Job execution is available in Grafana. Use the following label filter to find the relevant log entries:
240+
241+
```
242+
component: cronjob
243+
```
244+
245+
For details on how to access and query logs in Grafana, see [Logs](../monitoring/logs).
246+
247+
## Specifying Organization, Project, and Application
248+
249+
All commands accept optional flags to target a specific resource. If omitted, the CLI will auto-detect from your git remote or prompt you interactively.
250+
251+
```bash
252+
sw-paas application cronjob list \
253+
--organization-id <org-id> \
254+
--project-id <project-id> \
255+
--application-id <app-id>
256+
```
257+
258+
The short alias `cron` works for all commands:
259+
260+
```bash
261+
sw-paas application cron list
262+
sw-paas application cron history list
263+
```

0 commit comments

Comments
 (0)