Small lib for executing php callbacks using cron expression.
Install via composer.
composer require tlapnet/scheduler
Register extension.
extensions:
scheduler: Tlapnet\Scheduler\DI\SchedulerExtension
Set-up crontab. Use scheduler:run
command.
* * * * * php path-to-project/console scheduler:run
Optionally set temp path for lock files.
scheduler:
path: '%tempDir%/scheduler'
scheduler:
jobs:
- {cron: '* * * * *', callback: App\Model\Pirate::arrgghh}
- {cron: '*/2 * * * *', callback: App\Model\Parrot::echo}
Use IJob
interface.
class MyAwesomeJob implements IJob
{
/**
* @param DateTime $dateTime
* @return bool
*/
public function isDue(DateTime $dateTime)
{
return TRUE; // When is job ready to run
}
/**
* @return void
*/
public function run()
{
// Do something
}
}
And register it.
scheduler:
jobs:
- App\Model\MyAwesomeJob
List all jobs.
scheduler:list
Run all due jobs.
scheduler:run