https://github.com/mattmezza/php-scheduled-job
A package to run scheduled job with cron.
https://github.com/mattmezza/php-scheduled-job
cron cronjob crontab job-runner scheduled-jobs task-runner
Last synced: 6 months ago
JSON representation
A package to run scheduled job with cron.
- Host: GitHub
- URL: https://github.com/mattmezza/php-scheduled-job
- Owner: mattmezza
- License: mit
- Created: 2018-11-30T11:58:40.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-11T21:40:53.000Z (over 6 years ago)
- Last Synced: 2025-02-13T15:36:27.498Z (8 months ago)
- Topics: cron, cronjob, crontab, job-runner, scheduled-jobs, task-runner
- Language: PHP
- Homepage:
- Size: 16.6 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
scheduled job
=======[](https://github.com/mattmezza/php-scheduled-job)
## Installation
`composer require mattmezza/scheduled-job`
## Usage
##### 1. Create a task
```php
class MyTask extends TaskStandard {public function getDescriptionString(): string
{
return 'Task description';
}public function run(array $allParam)
{
// do something
}
}
```##### 2. Create a job
```php
class MyJob extends JobStandard {public function getDescriptionString(): string
{
return 'Job description';
}public function getAllTask(): array
{
return [
new MyTask(),
];
}
}
```##### 3. Run the job
```php
(new JobExecutorStandard())->execute($job, $argv]);
```##### 4. Observe jobs and tasks
You can attach observers to both jobs and tasks.
```php
$job->addObserver(new JobLogger());
$task->addObserver(new TaskLogger());
```You can define custom observers by implementing `JobObserver` and `TaskObserver`.
##### 5. Automate with cron
Create a PHP script file that you can run via cron `~/your-project/your-job.php`:
```php
#!/usr/bin/env phpexecute($job, $argv]);
} catch (YourException $error) {
// Oops, something happened...
}
```Add the cron entry in the crontab via `crontab -e`:
```
# run five minutes after midnight, every day
5 0 * * * $HOME/your-project/your-job.php >> $HOME/tmp/out 2>&1
```## Development
- [ ] Would be nice to add different kind of jobs each one specialized in a particular way (i.e. memory intensive etc...)