Skip to content

Commit

Permalink
Merge pull request #20 from spiral-packages/hotfix/schedule-runner
Browse files Browse the repository at this point in the history
Fixes an issue
  • Loading branch information
butschster authored Sep 30, 2024
2 parents 5af99b9 + 4bf6ce7 commit b07c617
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/EveryMinuteCommandRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b07c617

Please sign in to comment.