Laravel 5 schedule not working

My laravel version is 5.0.28, I am building on cloud9, I added this command to my cron

#!/bin/bash
PATH=/usr/bin
* * * * * php /home/ubuntu/workspace/app/artisan scheduled:run 1>> /dev/null 2>&1

      

And I add this code to mine Kernel.php

. I believe I am sitting https://laravel-news.com/2014/11/laravel-5-scheduler/

<?php namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use App\Http\Controllers\ApiController;

class Kernel extends ConsoleKernel {

    protected $commands = [
        'App\Console\Commands\Inspire',
    ];

    protected function schedule(Schedule $schedule)
    {
        $schedule->call('ApiController@test_job')->hourly();
    }
}

      

I am waiting and still not working and I am trying to use this command php artisan schedule:run

and I am getting this returnNo scheduled commands are ready to run.

I found this Laravel 5 answer "Class does not exist" when using the scheduler

I change my code and this code didn't set the time, so I change mine cron

, but it still doesn't work. I have no idea. please give me some, thanks.

code

$schedule->call(join('@', [ApiController::class, 'test_job']));

      

hron

0 0,3,6,9,12,15,18,21 * * * php /home/ubuntu/workspace/app/artisan schedule:run 1>> /dev/null 2>&1
30 1,4,7,10,13,16,19,22 * * * php /home/ubuntu/workspace/app/artisan schedule:run 1>> /dev/null 2>&1

      

+3


source to share


4 answers


Laravel's scheduler works with commands, not controller methods:

  • create command:
php artisan make:command PurchasePodcast

      

  1. edit command:
namespace App\Console\Commands;

use Illuminate\Console\Command;

class PurchasePodcast extends Command
{
    protected $name = 'purchase:podcast';

    public function fire()
    {
        // do stuff here
    }
}

      



  1. add command to Console\Kernel.php

    :
protected $commands = [
    'App\Console\Commands\PurchasePodcast',
];

      

  1. use the command in the scheduler:
$schedule->command('purchase:podcast')->hourly();

      

+6


source


first check if cron is running on your server or local type:

> sudo service cron status

      

if not installed:

> sudo apt-get install cron

      

to enable laravel scheduler:

> crontab -e

      



and you can choose an editor if vim doesn't open directly. Be sure to enter this line at the bottom here:

* * * * * php /path_from_root_to_laravel_proj_folder/artisan schedule:run 1>> /dev/null 2>&1

      

To check if the scheduler is configured correctly in laravel, run this from your projects folder:

>php artisan schedule:run

      

this should complete the tasks and tell you what it does.

+5


source


To complete @ limonte's answer, create a console command:

php artisan make:console CampaignsCollect --command=campaigns:collect

      

Link here: link

0


source


There are several aspects to find the cause: First check if the "timezone" is set correctly in config / app.php. Laravel will reset the timezone even if you've already configured it in php.ini. Second, make sure the crontab is working as expected. When you get the message "No schedule to be ready" it means that your crontab is running and may detect php and artisan command.

0


source







All Articles