Skip to content

Conversation

@dallyger
Copy link
Contributor

@dallyger dallyger commented Jan 23, 2025

Force to run the selected command in the foreground.

The artisan schedule:test command exited immediately after invocation and the selected command did not start if it uses ->runInBackground(). If ->withoutOverlapping() is used too, the mutex would not be removed and blocks any further execution without any user facing notice.

How to Reproduce

composer create-project <dir>
cd <dir
php artisan make:command TestCommand

Edit app/Console/Commands/TestCommand.php

     public function handle()
     {
-        //
+        Log::info("running");
     }

Edit bootstrap/app.php

+use App\Console\Commands\TestCommand;
+use Illuminate\Console\Scheduling\Schedule;
+
 return Application::configure(basePath: dirname(__DIR__))
+    ->withSchedule(function (Schedule $schedule) {
+        $schedule->command(TestCommand::class)
+            ->everyMinute()
+            ->runInBackground()
+            ->withoutOverlapping();
+    })

Observe logs: tail -f storage/logs/laravel.log

Run the scheduled command: php artisan schedule:test
Compare against: php artisan schedule:work

Force to run the selected command in the foreground.

The `artisan schedule:test` command exited immediately after invocation
and the selected command did not start if it uses `->runInBackground()`.
If `->withoutOverlapping()` is used too, the mutex would not be removed
and blocks any further execution without any user facing notice.
@taylorotwell taylorotwell merged commit e365c08 into laravel:11.x Jan 23, 2025
79 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants