Skip to content

Commit

Permalink
fix: replace deprecated chrono functions (lte, lt, gte, addMinute, ad…
Browse files Browse the repository at this point in the history
…dSecond) (#1531)

* fix: replace deprecated chronos functions (lte, lt, gte, addMinute, addSecond)

* style: fix code style according to StyleCI
  • Loading branch information
JHIH-LEI authored Jan 27, 2025
1 parent b3fba0d commit 4219de6
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Listeners/MonitorWaitTimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ protected function dueToMonitor()
*/
protected function timeToMonitor()
{
return Chronos::now()->subMinutes(1)->lte($this->lastMonitored);
return Chronos::now()->subMinutes(1)->lessThanOrEquals($this->lastMonitored);
}
}
2 changes: 1 addition & 1 deletion src/Listeners/TrimFailedJobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function handle(MasterSupervisorLooped $event)
$this->lastTrimmed = Chronos::now()->subMinutes($this->frequency + 1);
}

if ($this->lastTrimmed->lte(Chronos::now()->subMinutes($this->frequency))) {
if ($this->lastTrimmed->lessThanOrEquals(Chronos::now()->subMinutes($this->frequency))) {
app(JobRepository::class)->trimFailedJobs();

$this->lastTrimmed = Chronos::now();
Expand Down
2 changes: 1 addition & 1 deletion src/Listeners/TrimMonitoredJobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function handle(MasterSupervisorLooped $event)
$this->lastTrimmed = Chronos::now()->subMinutes($this->frequency + 1);
}

if ($this->lastTrimmed->lte(Chronos::now()->subMinutes($this->frequency))) {
if ($this->lastTrimmed->lessThanOrEquals(Chronos::now()->subMinutes($this->frequency))) {
app(JobRepository::class)->trimMonitoredJobs();

$this->lastTrimmed = Chronos::now();
Expand Down
2 changes: 1 addition & 1 deletion src/Listeners/TrimRecentJobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function handle(MasterSupervisorLooped $event)
$this->lastTrimmed = Chronos::now()->subMinutes($this->frequency + 1);
}

if ($this->lastTrimmed->lte(Chronos::now()->subMinutes($this->frequency))) {
if ($this->lastTrimmed->lessThanOrEquals(Chronos::now()->subMinutes($this->frequency))) {
app(JobRepository::class)->trimRecentJobs();

$this->lastTrimmed = Chronos::now();
Expand Down
3 changes: 2 additions & 1 deletion src/MasterSupervisor.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function terminate($status = 0)
// process does not get stuck in an infinite loop here waiting for these.
while (count($this->supervisors->filter->isRunning())) {
if (Chronos::now()->subSeconds($longest)
->gte($startedTerminating)) {
->greaterThanOrEquals($startedTerminating)) {
break;
}

Expand Down Expand Up @@ -217,6 +217,7 @@ public function monitor()
* Ensure that this is the only master supervisor running for this machine.
*
* @return void
*
* @throws \Exception
*/
public function ensureNoOtherMasterSupervisors()
Expand Down
2 changes: 1 addition & 1 deletion src/ProcessPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ protected function stopTerminatingProcessesThatAreHanging()
foreach ($this->terminatingProcesses as $process) {
$timeout = $this->options->timeout;

if ($process['terminatedAt']->addSeconds($timeout)->lte(Chronos::now())) {
if ($process['terminatedAt']->addSeconds($timeout)->lessThanOrEquals(Chronos::now())) {
$process['process']->stop();
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/Supervisor.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public function balance(array $balance)
foreach ($balance as $queue => $scale) {
$this->processPools->first(function ($pool) use ($queue) {
return $pool->queue() === $queue;
}, new class {
}, new class
{
public function __call($method, $arguments)
{
}
Expand Down Expand Up @@ -271,6 +272,7 @@ public function monitor()
* Ensure no other supervisors are running with the same name.
*
* @return void
*
* @throws \Exception
*/
public function ensureNoDuplicateSupervisors()
Expand Down Expand Up @@ -334,7 +336,7 @@ protected function autoScale()
$this->lastAutoScaled = $this->lastAutoScaled ?:
Chronos::now()->subSeconds($this->autoScaleCooldown + 1);

if (Chronos::now()->subSeconds($this->autoScaleCooldown)->gte($this->lastAutoScaled)) {
if (Chronos::now()->subSeconds($this->autoScaleCooldown)->greaterThanOrEquals($this->lastAutoScaled)) {
$this->lastAutoScaled = Chronos::now();

app(AutoScaler::class)->scale($this);
Expand Down
6 changes: 3 additions & 3 deletions src/WorkerProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ protected function cooldown()

if ($this->restartAgainAt) {
$this->restartAgainAt = ! $this->process->isRunning()
? Chronos::now()->addMinute()
? Chronos::now()->addMinutes(1)
: null;

if (! $this->process->isRunning()) {
event(new UnableToLaunchProcess($this));
}
} else {
$this->restartAgainAt = Chronos::now()->addSecond();
$this->restartAgainAt = Chronos::now()->addSeconds(1);
}
}

Expand All @@ -178,7 +178,7 @@ protected function cooldown()
public function coolingDown()
{
return isset($this->restartAgainAt) &&
Chronos::now()->lt($this->restartAgainAt);
Chronos::now()->lessThan($this->restartAgainAt);
}

/**
Expand Down

0 comments on commit 4219de6

Please sign in to comment.