2
  • Laravel Version: 5.7.25
  • PHP Version: 7.2.14
  • Database Driver & Version: MySQL 2ª gen. 5.7

Hi, Sorry for the trouble, I have this problem in creating a scheduled command.

Description:

In our crontab -e user we have inserted the following on Debian:

* * * * * cd /var/www/myfolder.com/ && php artisan schedule:run >> crontab.laravel

We have correctly entered the schedule function as follows:

app/console/kernel.php

  <?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;


class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
//        'App\Console\Commands\HelpCenter',
        Commands\HelpCenter::class
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('elena:help')->everyMinute();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__ . '/Commands');

        require base_path('routes/console.php');
    }

}

but the result continues to be No scheduled commands are ready to run we tried all the combinations impossible but nothing. If we uncomment the function Artisan call working, the script is executed

Try to force command crontab -e

To better understand where the problem lies We have added a crontab directly with the command without going through the schedule as :

* * * * * cd /var/www/myfolder.com/ && php artisan elena:help >> crontab.laravel

This command runs perfectly every minute so we can not figure out where the problem is. if you have the patience to give us some advice we will be happy. good day

Mwspace LLC
  • 105
  • 3
  • 4
  • Did you do this with sudo? `sudo crontab -e` – Michael Mano Feb 11 '19 at 10:59
  • 2
    Did you run `php artisan cache:clear`? There might be a schedule file cached in your storage/framework folder. – piscator Feb 11 '19 at 11:25
  • Yes @piscator . All. Check info -> https://laracasts.com/discuss/channels/laravel/no-scheduled-commands-are-ready-to-run-empty#reply=491513 – Mwspace LLC Feb 11 '19 at 12:22
  • @MichaelMano no, not in sudo crontab ️‍♀️ – Mwspace LLC Feb 11 '19 at 12:23
  • Check [this](https://stackoverflow.com/questions/30700396/laravel-no-scheduled-commands-are-ready-to-run), talks about similar problems – Mihir Bhende Feb 12 '19 at 00:03
  • Are you *absolutely sure* that this is the code running in your Kernel.php on the server, and it's not a simple mistake like not copying the new file? I've read through the laracasts thread and it seems like everything has been tried. Maybe there's a weird php caching bug (has happened to me) and you could try a server reboot? And `php artisan up`? – Travis Britz Feb 12 '19 at 06:18
  • 1
    @piscator That was it! There was a schedule cached. Once cleared the cache, the command ran. Thanks. – Gjaa Sep 13 '19 at 19:24

2 Answers2

11

I copy this here because this solved my issue. It's @piscator comment above.

"Did you run php artisan cache:clear? There might be a schedule file cached in your storage/framework folder."

EDIT:

This issue was giving me a lot of trouble. I'm using Laravel 5.8 and I couldn't make it work with ->withoutOverlapping(); The task will die after a while without apparent reasons and then the cron job couldn't start it again because ->withoutOverlapping() was preventing it.

Finally I found a solution here:

Basically, instead of using Laravel's ->withoutOverlapping(), you check yourself if the task is already running.

// start the queue worker, if its not running
$command = "queue:work --queue=high,email,default,low --tries=3 --delay=3";
if (!$this->osProcessIsRunning($command)) {
    $schedule->command($command)->everyMinute()
                                ->runInBackground()
                                ->appendOutputTo(storage_path('logs/queue.log'));
}

// function for checking if the task is running
protected function osProcessIsRunning($needle)
{
    // get process status. the "-ww"-option is important to get the full output!
    exec('ps aux -ww', $process_status);

    // search $needle in process status
    $result = array_filter($process_status, function($var) use ($needle) {
        return strpos($var, $needle);
    });

    // if the result is not empty, the needle exists in running processes
    if (!empty($result)) {
        return true;
    }
    return false;
}

Thanks to @henryonsoftware for the solution

Gjaa
  • 1,461
  • 1
  • 19
  • 20
0

I don't know if I am late, but I have a solution for you. JUST ADD THE TIMEZONE IN THE SCHEDULE METHOD. it will start working well.

Example:

$schedule->command('tenam:before')
        ->dailyAt('22:28')->timezone('Asia/Kolkata');
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 13 '22 at 22:47