Skip to content

Commit cfdf302

Browse files
committed
Rewrite cronjob doc from scratch
1 parent 4b5da19 commit cfdf302

4 files changed

Lines changed: 86 additions & 40 deletions

File tree

docs/administration/recent_activity/recent_activity.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ ibexa:
3434
activity_logs_limit: 20
3535
```
3636
37-
To automate a regular truncation, the command `ibexa:activity-log:truncate` must be added to a crontab.
37+
To automate a regular truncation, the command `ibexa:activity-log:truncate` must be added to a cron job.
3838
To minimize the number of entries to delete, it's recommended to execute the command more than one time a day.
3939

40-
For every exact hour, the cronjob line is:
41-
`0 * * * * cd [path-to-ibexa]; php bin/console ibexa:activity-log:truncate --quiet --env=prod`
40+
For more information, see [Additional cron jobs and advanced usage](install_ibexa_dxp.md#additional-cron-jobs-and-advanced-usage).
4241

4342
## Permission and security
4443

docs/cdp/cdp_data_export_schedule.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,8 @@ php bin/console ibexa:cdp:stream-product-data --help
6565

6666
```bash
6767
php bin/console ibexa:cdp:stream-content-data --help
68-
```
68+
```
69+
70+
The configuration is executed by `ibexa:cron:run` command which must be configured as a cron job.
71+
72+
For more information, see [Scheduling cron jobs](install_ibexa_dxp.md#scheduling-cron-jobs).

docs/content_management/url_management/url_management.md

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,7 @@ The following protocols are currently supported:
3737

3838
To enable automatic URL validation, set up cron to run the `ibexa:check-urls` command periodically.
3939

40-
For example, to check links every week, add the following script:
41-
42-
```
43-
echo '0 0 * * 0 cd [path-to-ibexa]; php bin/console ibexa:check-urls --quiet --env=prod' > ibexa_cron.txt
44-
```
45-
46-
Next, append the new cron to user's crontab without destroying existing crons.
47-
Assuming that the web server user data is www-data:
48-
49-
```
50-
crontab -u www-data -l | cat - ibexa_cron.txt | crontab -u www-data -
51-
```
52-
53-
Finally, remove the temporary file:
54-
55-
```
56-
rm ibexa_cron.txt
57-
```
40+
For more information, see [Additional cron jobs and advanced usage](install_ibexa_dxp.md#additional-cron-jobs-and-advanced-usage).
5841

5942
### Configuration
6043

docs/getting_started/install_ibexa_dxp.md

Lines changed: 78 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ Prepare a [virtual host configuration](https://en.wikipedia.org/wiki/Virtual_hos
379379

380380
You can use [this example vhost file](https://raw.githubusercontent.com/ibexa/post-install/main/resources/templates/nginx/vhost.template) and modify it to fit your project. You also need the `ibexa_params.d` files that should reside in a subdirectory below where the main file is, [as is shown here](https://github.com/ibexa/post-install/tree/main/resources/templates/nginx).
381381

382-
383382
Specify `/<your installation directory>/public` as the `root`, or ensure `BASEDIR` is set in the environment.
384383
Ensure `APP_ENV` is set to `prod` or `dev` in the environment, depending on the environment that you're configuring, and uncomment the line that starts with `#if[APP_ENV`.
385384

@@ -396,36 +395,97 @@ You should see the welcome page.
396395

397396
See the [Security checklist](security_checklist.md) for a list of security-related issues you should take care of before going live with a project.
398397

399-
### Enable Date-based Publisher
398+
### Scheduling cron jobs
399+
400+
The `ibexa:cron:run` command executes all service commands tagged `ibexa.cron.job`.
401+
It should be scheduled to run every minute.
400402

401-
To enable delayed publishing of content items using the Date-based Publisher, you must set up cron to run the `ibexa:scheduled:run` command periodically.
402-
This command service is tagged `ibexa.cron.job`.
403-
The `ibexa:cron:run` executes all service commands tagged `ibexa.cron.job`.
403+
The following example, creates a temporary file with the crontab line to appends it to existing web server's crontab, assuming the web server user is `www-data`:
404404

405-
For example, to check for publishing every minute, add the following script:
405+
```bash
406+
echo '* * * * * cd <path-to-ibexa-dxp>; php bin/console ibexa:cron:run --quiet --env=prod' > ibexa_cron.txt
407+
crontab -u www-data -l | cat - ibexa_cron.txt | crontab -u www-data -
408+
rm ibexa_cron.txt
409+
```
406410

407-
`echo '* * * * * cd [path-to-ibexa-dxp]; php bin/console ibexa:cron:run --quiet --env=prod' > ibexa_cron.txt`
411+
For [Scheduled content publications]([[= user_doc =]]/content_management/schedule_publishing/), `ibexa:scheduled:run` command service is tagged `ibexa.cron.job` with, by default, a frequency of every minute (`* * * * *`).
412+
If needed, you can redefine this service to set up another frequency.
408413

409-
For 5-minute intervals:
414+
The [CDP data export schedule](cdp_data_export_schedule.md) also uses `ibexa.cron.job` tagged services under the hood.
410415

411-
`echo '*/5 * * * * cd [path-to-ibexa-dxp]; php bin/console ibexa:cron:run --quiet --env=prod' > ibexa_cron.txt`
416+
You can add other commands to the cron either by:
412417

413-
Next, append the new cron to user's crontab without destroying existing crons.
414-
Assuming the web server user is `www-data`:
418+
- Adding their own scheduling line to the crontab
419+
- Tagging their service with `ibexa.cron.job`
415420

416-
`crontab -u www-data -l | cat - ibexa_cron.txt | crontab -u www-data -`
421+
#### Additional cron jobs and advanced usage
417422

418-
Finally, remove the temporary file:
423+
To make use of the [Link Manager](url_management.md#enabling-automatic-url-validation), schedule the link validating command `ibexa:check-urls`.
419424

420-
`rm ibexa_cron.txt`
425+
To [control the recent activity log size](recent_activity.md#configuration-and-cronjob), schedule the `ibexa:activity-log:truncate` command.
421426

422-
### Enable the Link manager
427+
The following example schedule separetely:
423428

424-
To make use of the [Link Manager](url_management.md#enabling-automatic-url-validation).
429+
- `ibexa:cron:run` every minute
430+
- `ibexa:check-urls` every week (on Sunday at midnight)
431+
- `ibexa:activity-log:truncate` every exact hour (on 0th minute)
425432

426-
### Enable recent activity log truncation
433+
This shell script create a temporary file with the job lines, then override and replace the existing web crontab.
427434

428-
To [control the log size](recent_activity.md#configuration-and-cronjob).
435+
```bash
436+
echo '* * * * * cd <path-to-ibexa-dxp>; php bin/console ibexa:cron:run --quiet --env=prod' > ibexa_cron.txt
437+
echo '0 0 * * 0 cd <path-to-ibexa-dxp>; php bin/console ibexa:check-urls --quiet --env=prod' >> ibexa_cron.txt
438+
echo '0 * * * * cd <path-to-ibexa-dxp>; php bin/console ibexa:activity-log:truncate --quiet --env=prod' >> ibexa_cron.txt
439+
crontab -u www-data - ibexa_cron.txt
440+
rm ibexa_cron.txt
441+
```
442+
443+
The following alternative example, use the service tagging to schedule them.
444+
It also changes the `ibexa:scheduled:run` frequency to every five minutes.
445+
446+
Appended to `config/services.yaml`:
447+
448+
```
449+
services:
450+
#…
451+
452+
Ibexa\Bundle\Scheduler\Command\ScheduledRunCommand:
453+
tags:
454+
- { name: ibexa.cron.job, schedule: '*/5 * * * *' }
455+
456+
Ibexa\Bundle\Core\Command\CheckURLsCommand:
457+
arguments:
458+
$urlChecker: '@Ibexa\Bundle\Core\URLChecker\URLChecker'
459+
tags:
460+
- { name: ibexa.cron.job, schedule: '0 0 * * 0' }
461+
462+
Ibexa\Bundle\ActivityLog\Command\TruncateLogCommand:
463+
tags:
464+
- { name: ibexa.cron.job, schedule: '0 * * * *' }
465+
```
466+
467+
The `ibexa.cron.job` tag accepts the following options.
468+
469+
- `schedule`: A cron expression representing the period or interval.
470+
- `options`: Arguments passed to the command, notice that the `--env` and `--siteaccess` options are passed to the command from `ibexa:cron:run` command.
471+
- `category`: Commands can be grouped in categories, then a category can be passed with `ibexa:cron:run --category=<CATEGORY>`, by default, a `default` category is set and used.
472+
For example, it can be used to set different jobs and `schedule` for different SiteAccesses.
473+
- `priority`: To defined in which order the `ibexa:cron:run` run the commands that need to be.
474+
475+
The following command add the scheduling of `ibexa:cron:run` for a SiteAccess `minor_website` and a job category `minor_website`:
476+
477+
```bash
478+
(crontab -u www-data -l; echo '* * * * * cd <path-to-ibexa-dxp>; php bin/console ibexa:cron:run --quiet --env=prod --siteaccess=minor_website --category=minor_website') | crontab -u www-data -
479+
```
480+
481+
So, `ibexa:scheduled:run` can now be run on this SiteAccess with another frequency than the default:
482+
483+
```
484+
Ibexa\Bundle\Scheduler\Command\ScheduledRunCommand:
485+
tags:
486+
- { name: ibexa.cron.job, schedule: '* * * * *' }
487+
- { name: ibexa.cron.job, schedule: '*/5 * * * *', category: 'minor_website' }
488+
```
429489

430490
## [[= product_name_cloud =]]
431491

0 commit comments

Comments
 (0)