Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nojimage/cakephp-cron-jobs
A cron job runner for CakePHP
https://github.com/nojimage/cakephp-cron-jobs
cakephp cakephp-plugin cron schedule scheduler
Last synced: about 2 months ago
JSON representation
A cron job runner for CakePHP
- Host: GitHub
- URL: https://github.com/nojimage/cakephp-cron-jobs
- Owner: nojimage
- License: mit
- Created: 2019-11-09T06:17:23.000Z (almost 5 years ago)
- Default Branch: cake5
- Last Pushed: 2024-05-01T09:32:33.000Z (5 months ago)
- Last Synced: 2024-06-29T20:01:15.489Z (3 months ago)
- Topics: cakephp, cakephp-plugin, cron, schedule, scheduler
- Language: PHP
- Homepage:
- Size: 43 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# A cron job runner for CakePHP
This plugin is simple wrapper [crunzphp/crunz](https://github.com/crunzphp/crunz).
## Version Map
| CakePHP Version | Plugin Version | Branch |
|-----------------|----------------|----------------|
| 5.x | 3.x | cake5 |
| 4.x | 2.x | cake4 |
| 3.x | 0.3.x | cake3 |## Installation
You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).
The recommended way to install composer packages is:
```
composer require elstc/cakephp-cron-jobs
```### Load plugin
Load the plugin by adding the following statement in your project's `src/Application.php`:
```
$this->addPlugin('Elastic/CronJobs');
```### Generate config file
Run `bin/cake CronJobs publish:config` command.
The command generate `crunz.yml` in the project `ROOT` directory.You can configure with `crunz.yml`, see also [https://github.com/crunzphp/crunz#configuration](https://github.com/crunzphp/crunz#configuration)
I recommend changing `source:` to:
```yaml
source: vendor/elstc/cakephp-cron-jobs/tasks
```This makes it unnecessary to specify a directory when using `schedule:run` and `schedule:list` command.
### Register to cron
add your cron schedule, use `crontab -e`
```
* * * * * cd {YOUR-APP-DIR}; bin/cake CronJobs schedule:run vendor/elstc/cakephp-cron-jobs/tasks/
```## Usage
You can register a schedule job from the CakePHP event system.
Register to job schduler in bootstrap_cli.php, using cakephp event system:
```php
use Cake\Event\Event;
use Cake\Event\EventManager;EventManager::instance()->on('CronJobs.buildSchedule', static function (Event $event) {
/** @type \Elastic\CronJobs\Schedule\CakeSchedule $schedule */
$schedule = $event->getSubject();
// Add scheduled command
$schedule->run('touch tmp/crunz-time-from-event')
->description('your job description')
->everyDay()
->at('09:00');// Add scheduled cake's command
// such as `bin/cake your_command comannd_arg1 --command-option --some-opt=value`
$schedule->runCommand('your_command', [
'comannd_arg1',
'--command-option',
'--some-opt' => 'value',
])
->description('your job description')
->cron('0 3 * * *');
});
````\Elastic\CronJobs\Schedule\CakeSchedule` is `\Crunz\Schedule` wrapper class.
See also: [crunzphp/crunz README](https://github.com/crunzphp/crunz#crunz)### Show scheduled jobs
```sh
bin/cake CronJobs schedule:list vendor/elstc/cakephp-cron-jobs/tasks/
```### Upgrade from CakePHP 3
larvery/crunz updated from 1.12 to 2.x(<= PHP 7.3), 3.x(>= PHP 7.4), See also crunz's Upgrade Guide.
[crunz/UPGRADE\.md at master · crunzphp/crunz](https://github.com/crunzphp/crunz/blob/master/UPGRADE.md)