diff --git a/README.md b/README.md index 7ce7ff4..55531c8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ [![PHP](https://img.shields.io/packagist/php-v/spiral-packages/scheduler.svg?style=flat-square)](https://packagist.org/packages/spiral-packages/scheduler) [![Latest Version on Packagist](https://img.shields.io/packagist/v/spiral-packages/scheduler.svg?style=flat-square)](https://packagist.org/packages/spiral-packages/scheduler) -[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/spiral-packages/scheduler/run-tests?label=tests&style=flat-square)](https://github.com/spiral-packages/scheduler/actions?query=workflow%3Arun-tests) +[![run-tests](https://github.com/spiral-packages/scheduler/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spiral-packages/scheduler/actions/workflows/run-tests.yml) +[![static-analysis ](https://github.com/spiral-packages/scheduler/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/spiral-packages/scheduler/actions/workflows/static-analysis.yml) [![Total Downloads](https://img.shields.io/packagist/dt/spiral-packages/scheduler.svg?style=flat-square)](https://packagist.org/packages/spiral-packages/scheduler) This is a cron jobs scheduler that can be easily integrated with your project based on spiral framework. The idea was diff --git a/src/EveryMinuteCommandRunner.php b/src/EveryMinuteCommandRunner.php index f4d7ac1..0a8c2d9 100644 --- a/src/EveryMinuteCommandRunner.php +++ b/src/EveryMinuteCommandRunner.php @@ -22,7 +22,8 @@ public function __construct( public function run(string $command, \Closure $onSuccess = null, \Closure $onError = null): void { while (true) { - $this->waitMinute(); + // Wait 100ms before checking if the process should be executed + $this->wait(); if ($this->shouldProcessBeExecuted()) { $this->executions[] = $execution = $this->processFactory @@ -61,10 +62,10 @@ private function now(): Carbon private function shouldProcessBeExecuted(): bool { return $this->now()->second === 0 - && ! $this->now()->startOfMinute()->equalTo($this->lastExecutionStartedAt); + && ($this->lastExecutionStartedAt === null || ! $this->now()->startOfMinute()->equalTo($this->lastExecutionStartedAt)); } - private function waitMinute(): void + private function wait(): void { \usleep(100 * 1000); }