for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Jellyfish\Scheduler;
use DateTime;
class Scheduler implements SchedulerInterface
{
protected const DELAY_INTERVAL = 1000000;
/**
* @var JobInterface[]
*/
protected $jobs;
protected $runningJobs = [];
* Scheduler constructor
public function __construct()
$this->jobs = [];
$this->runningJobs = [];
}
* @param \Jellyfish\Scheduler\JobInterface $job
*
* @return \Jellyfish\Scheduler\SchedulerInterface
public function queueJob(JobInterface $job): SchedulerInterface
$this->jobs[] = $job;
return $this;
public function clearJobs(): SchedulerInterface
* @throws \Exception
public function run(): SchedulerInterface
$dateTime = new DateTime();
foreach ($this->jobs as $job) {
$this->runningJobs[] = $job->run($dateTime);
while (count($this->runningJobs) !== 0) {
foreach ($this->runningJobs as $index => $runningJob) {
if ($runningJob->isRunning()) {
continue;
unset($this->runningJobs[$index]);
usleep(static::DELAY_INTERVAL);
* @return \Jellyfish\Scheduler\JobInterface[]
public function getQueuedJobs(): array
return $this->jobs;