yolo / scheduler
A scheduler package.
v1.0.0
2024-07-12 09:51 UTC
This package is not auto-updated.
Last update: 2025-03-22 11:42:55 UTC
README
Install
composer require yolo/scheduler
Usage
- Add to ServiceStartListener::process()
<?php
namespace App\Listener;
use Hyperf\Event\Contract\ListenerInterface; use Hyperf\Framework\Event\AfterWorkerStart; use Hyperf\Event\Annotation\Listener; use Yolo\Scheduler\SchedulerRunner;
[Listener]
class ServiceStartListener implements ListenerInterface {
public function listen(): array
{
return [
AfterWorkerStart::class,
];
}
public function process(object $event): void
{
(new SchedulerRunner())->run();
}
}
- Create a task
<?php
namespace App\Schedulers;
use Yolo\Log\Log; use Yolo\Scheduler\AbstractScheduler;
class TestScheduler extends AbstractScheduler {
protected string $name = 'TestScheduler';
protected bool $rightNow = true;
protected int $interval = 10;
public function handle(): int
{
echo('Handling task: ' . $this->name . PHP_EOL);
return 0;
}
}
- Add to config/config.php
return [
'schedulers' => [
\App\Schedulers\TestScheduler::class
],
]