8000 [8.x] Ensure event mutex is always removed (#39498) · laravel/framework@32da5eb · GitHub
[go: up one dir, main page]

Skip to content

Commit 32da5eb

Browse files
[8.x] Ensure event mutex is always removed (#39498)
* Ensure mutex is always removed * formatting * Remove after callback that duplicates work * rename method Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 915d44e commit 32da5eb

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

src/Illuminate/Console/Scheduling/Event.php

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Illuminate\Support\Traits\ReflectsClosures;
1818
use Psr\Http\Client\ClientExceptionInterface;
1919
use Symfony\Component\Process\Process;
20+
use Throwable;
2021

2122
class Event
2223
{
@@ -218,11 +219,17 @@ public function mutexName()
218219
*/
219220
protected function runCommandInForeground(Container $container)
220221
{
221-
$this->callBeforeCallbacks($container);
222+
try {
223+
$this->callBeforeCallbacks($container);
222224

223-
$this->exitCode = Process::fromShellCommandline($this->buildCommand(), base_path(), null, null, null)->run();
225+
$this->exitCode = Process::fromShellCommandline(
226+
$this->buildCommand(), base_path(), null, null, null
227+
)->run();
224228

225-
$this->callAfterCallbacks($container);
229+
$this->callAfterCallbacks($container);
230+
} finally {
231+
$this->removeMutex();
232+
}
226233
}
227234

228235
/**
@@ -233,9 +240,15 @@ protected function runCommandInForeground(Container $container)
233240
*/
234241
protected function runCommandInBackground(Container $container)
235242
{
236-
$this->callBeforeCallbacks($container);
243+
try {
244+
$this->callBeforeCallbacks($container);
245+
246+
Process::fromShellCommandline($this->buildCommand(), base_path(), null, null, null)->run();
247+
} catch (Throwable $exception) {
248+
$this->removeMutex();
237249

238-
Process::fromShellCommandline($this->buildCommand(), base_path(), null, null, null)->run();
250+
throw $exception;
251+
}
239252
}
240253

241254
/**
@@ -275,7 +288,11 @@ public function callAfterCallbacksWithExitCode(Container $container, $exitCode)
275288
{
276289
$this->exitCode = (int) $exitCode;
277290

278-
$this->callAfterCallbacks($container);
291+
try {
292+
$this->callAfterCallbacks($container);
293+
} finally {
294+
$this->removeMutex();
295+
}
279296
}
280297

281298
/**
@@ -647,9 +664,7 @@ public function withoutOverlapping($expiresAt = 1440)
647664

648665
$this->expiresAt = $expiresAt;
649666

650-
return $this->then(function () {
651-
$this->mutex->forget($this);
652-
})->skip(function () {
667+
return $this->skip(function () {
653668
return $this->mutex->exists($this);
654669
});
655670
}
@@ -915,4 +930,16 @@ public function preventOverlapsUsing(EventMutex $mutex)
915930

916931
return $this;
917932
}
933+
934+
/**
935+
* Delete the mutex for the event.
936+
*
937+
* @return void
938+
*/
939+
protected function removeMutex()
940+
{
941+
if ($this->withoutOverlapping) {
942+
$this->mutex->forget($this);
943+
}
944+
}
918945
}

0 commit comments

Comments
 (0)
0