#Issue: Laravel Artisan Scheduled Command Fails to Run with sail artisan schedule:run

10 messages · Page 1 of 1 (latest)

pliant ether
#

Hello everyone,

I'm working on a Laravel project where I'm using an Artisan console command to generate lottery draws (draws:generate) and a scheduler to ensure it runs at specific times (Tuesday, Thursday, and Saturday at 21:40). However, when I run the scheduler using the command sail artisan schedule:run -vvv, I receive the following output:

  2025-01-25 21:40:00 Running ['artisan' draws:generate] ........................................... 495.31ms FAIL
  ⇂ '/usr/bin/php8.4' 'artisan' draws:generate > '/dev/null' 2>&1  

What I've Done:

  • I created a command draws:generate and registered it in App\Console\Commands.
  • I also added the following Artisan command in the console.php:
<?php

use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schedule;

// Rejestracja komendy Artisan
Artisan::command('draws:generate', function () {
    $this->call('draws:generate');
})->purpose('Generowanie losowań');

// Scheduler w dni losowań (wtorek, czwartek, sobota) o 21:40
Schedule::command('draws:generate')->cron('40 21 * * 2,4,6');

Artisan::command('test:example', function () {
    $this->info('Testowa komenda działa!');
});

Expected Behavior:
The draws:generate command should be executed at 21:40 on Tuesdays, Thursdays, and Saturdays without any errors.

Problem:
The command fails to run, as indicated by the FAIL status, but the error details are suppressed by the redirection (> '/dev/null' 2>&1).

Code in Commands/GenerateDraws
https://pastebin.com/KyxxLDb8

restive parcel
final solar
#

Looks like your command calls itself immediately.

pliant ether
ruby kernel
#

Like mono said, the scheduler works, as you can see in the output it is executed. However, the command itself is failing. So you'd need to debug that, look at the logs why it's failing, or even send the command output to your email; https://laravel.com/docs/11.x/scheduling#task-output

final solar
#

I doubt that the command outputs anything. The very first line in the command sends it into infinite recursion. I'd check the server/fpm logs for a stack overflow error. On Windows I believe it even triggers a segfault in some cases.

pliant ether
#
Segmentation fault
#

This is the log it gave me to file

ionic gorge
#

Like mono said, your command seems to call itself... you should try to change the name of the artisan command you added in console.php so it doesn't call itself

pliant ether
#

Forgive me I was so tired that I misunderstood in English, in the morning I will try to correct and let you know what happens next.

For this moment, thank you all for your guidance