setono / cron-builder
Build cron files from a config in your repository
Installs: 23 648
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 4
Requires
- php: >=7.4
- ext-mbstring: *
- dragonmantank/cron-expression: ^2.0 || ^3.0
- symfony/config: ^4.4 || ^5.4 || ^6.0
- symfony/expression-language: ^4.4 || ^5.4 || ^6.0
- symfony/finder: ^4.4 || ^5.4 || ^6.0
- symfony/options-resolver: ^4.4 || ^5.4 || ^6.0
- symfony/process: ^4.4 || ^5.4 || ^6.0
- symfony/yaml: ^4.4 || ^5.4 || ^6.0
- thecodingmachine/safe: ^1.0
- webmozart/assert: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.3
- setono/code-quality-pack: ^1.4
This package is auto-updated.
Last update: 2023-11-11 10:36:53 UTC
README
Installation
$ composer require setono/cron-builder
Usage
The following two code snippets outlines the simplest usage of the cron builder.
1. Add your commands
The default directory to look for cronjobs is inside etc/cronjobs
. This can be changed in the options of the CronBuilder
.
Here we define two jobs. Two PHP commands that run on the given time.
# etc/cronjobs/jobs.yaml - schedule: "0 0 * * *" command: "php first-script.php" - schedule: "1 0 * * *" command: "php second-script.php"
2. Build the crontab
When your cronjobs are defined, you can build the crontab file:
<?php use Setono\CronBuilder\CronBuilder; $cronBuilder = new CronBuilder(); $crontab = $cronBuilder->build();
This will output the following:
###> Automatically generated by Setono Cron Builder - Do not edit ###
0 0 * * * php first-script.php
1 0 * * * php second-script.php
###< Automatically generated by Setono Cron Builder - Do not edit ###
You can save this in a file named crontab.txt
and add it to your crontab like this:
$ cat crontab.txt | crontab -