composer require mattmezza/scheduled-job
class MyTask extends TaskStandard {
public function getDescriptionString(): string
{
return 'Task description';
}
public function run(array $allParam)
{
// do something
}
}
class MyJob extends JobStandard {
public function getDescriptionString(): string
{
return 'Job description';
}
public function getAllTask(): array
{
return [
new MyTask(),
];
}
}
(new JobExecutorStandard())->execute($job, $argv]);
You can attach observers to both jobs and tasks.
$job->addObserver(new JobLogger());
$task->addObserver(new TaskLogger());
You can define custom observers by implementing JobObserver
and TaskObserver
.
Create a PHP script file that you can run via cron ~/your-project/your-job.php
:
#!/usr/bin/env php
<?php
$job = ... # create the job as above
try {
(new JobExecutorStandard())->execute($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
- Would be nice to add different kind of jobs each one specialized in a particular way (i.e. memory intensive etc...)