8000 [8.x] Ensure event mutex is always removed by inxilpro · Pull Request #39498 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[8.x] Ensure event mutex is always removed #39498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 7, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Ensure mutex is always removed
  • Loading branch information
inxilpro committed Nov 5, 2021
commit c30ff76aac18af16aad3bcabe4f5826f48d54dfa
41 changes: 35 additions & 6 deletions src/Illuminate/Console/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Illuminate\Support\Traits\ReflectsClosures;
use Psr\Http\Client\ClientExceptionInterface;
use Symfony\Component\Process\Process;
use Throwable;

class Event
{
Expand Down Expand Up @@ -218,11 +219,17 @@ public function mutexName()
*/
protected function runCommandInForeground(Container $container)
{
$this->callBeforeCallbacks($container);
try {
$this->callBeforeCallbacks($container);

$this->exitCode = Process::fromShellCommandline($this->buildCommand(), base_path(), null, null, null)->run();
$this->exitCode = Process::fromShellCommandline(
$this->buildCommand(), base_path(), null, null, null
)->run();

$this->callAfterCallbacks($container);
$this->callAfterCallbacks($container);
} finally {
$this->removeMutex();
}
}

/**
Expand All @@ -233,9 +240,15 @@ protected function runCommandInForeground(Container $container)
*/
protected function runCommandInBackground(Container $container)
{
$this->callBeforeCallbacks($container);
try {
$this->callBeforeCallbacks($container);

Process::fromShellCommandline($this->buildCommand(), base_path(), null, null, null)->run();
} catch (Throwable $exception) {
$this->removeMutex();

Process::fromShellCommandline($this->buildCommand(), base_path(), null, null, null)->run();
throw $exception;
}
}

/**
Expand Down Expand Up @@ -275,7 +288,11 @@ public function callAfterCallbacksWithExitCode(Container $container, $exitCode)
{
$this->exitCode = (int) $exitCode;

$this->callAfterCallbacks($container);
try {
$this->callAfterCallbacks($container);
} finally {
$this->removeMutex();
}
}

/**
Expand Down Expand Up @@ -635,6 +652,18 @@ public function evenInMaintenanceMode()
return $this;
}

/**
* Clear the mutex for the event.
*
* @return void
*/
protected function removeMutex()
{
if ($this->withoutOverlapping) {
$this->mutex->forget($this);
}
}

/**
* Do not allow the event to overlap each other.
*
Expand Down
0