Laravel schedule:run does not work - laravel-5

I am trying Laravel schedule command to run some background process for sending mails and fetching emails. When I run these commands individually using artisan they all run, but when I try to run shcedule:run command to run these commands
it shows "No scheduled commands are ready to run."
I've tried to look for an answer but nothing worked. So I tried to rectify the problem by running simple command and check the output.
Below is my kernal.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 = [
Commands\Inspire::class,
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')
->everyMinute();
dd($schedule);
}
}
when I run schedule:run it shows this output.
Bhanu-Slathias-MacBook-Pro:Faveo-Helpdesk-Pro-bhanu-fork vijaysebastian$ php artisan schedule:run
Illuminate\Console\Scheduling\Schedule {#54
#events: array:1 [
0 => Illuminate\Console\Scheduling\Event {#1663
+command: "'/Applications/AMPPS/php-5.6/bin/php' 'artisan' inspire"
+expression: "* * * * * *"
+timezone: null
+user: null
+environments: []
+evenInMaintenanceMode: false
+withoutOverlapping: false
+runInBackground: false
#filters: []
#rejects: []
+output: "/dev/null"
#shouldAppendOutput: false
#beforeCallbacks: []
#afterCallbacks: []
+description: null
}
But when I remove dd() in schedule() function the output is
No scheduled commands are ready to run.
Can anyone help me and tell what I am doing wrong.

Check out the storage/framework folder for files like that schedule-d71c52cd9f206ba2359601745a5ad13d51fa7ca6
If any - delete them and try to run schedule:run command again.

Related

Laravel Schedule Only Exceute Command on first Run

I create a schedule to send email everyday, but for testing if it works i make it run every minute.
here is my kernel.php
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* #var array
*/
protected $commands = [
Commands\SendExpiredReminder::class,
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->command('reminder:send')
->everyMinute();
}
/**
* Register the commands for the application.
*
* #return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
it run every minute but reminder:send only called first time i run the schedule with php /var/www/html/artisan schedule:run >> /dev/null 2>&1
when i run php /var/www/html/artisan schedule:list it show that next due is next minute indicated the scheduler is running. What is going wrong?
your crontab should be to your laravel project folder, not www folder
* * * * * cd /var/www/html/artisan && php artisan schedule:run >> /dev/null 2>&1
note the project folder

How to let cron decide the time to run laravel schedule daily?

I don't want to set server cron to run every minute (* * * * *) so I set it to #daily
#daily usr/bin/php /home/dss/laravelAppDss/artisan schedule:run >> /home/dss/public_html/example.txt
This is my 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\SinkronDataDosen',
'\App\Console\Commands\SinkronDataMahasiswa',
'\App\Console\Commands\SinkronPotensiDO',
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('SinkronDataDosen');
$schedule->command('SinkronDataMahasiswa');
$schedule->command('SinkronPotensiDO');
}
/**
* Register the Closure based commands for the application.
*
* #return void
*/
protected function commands()
{
require base_path('routes/console.php');
}
}
But it doesn't sync the data
This is the output example.txt
Running scheduled command: '/usr/bin/php7.0' 'artisan' SinkronDataDosen > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7.0' 'artisan' SinkronDataMahasiswa > '/dev/null' 2>&1
Running scheduled command: '/usr/bin/php7.0' 'artisan' SinkronPotensiDO > '/dev/null' 2>&1
The commands worked if I run each command signature individually so there is nothing wrong with the commands
How do I solve it?

why cron job stoped in new year 2021 in laravel

every thing works fine till 31 decemeber 2020 and in new year my cron job stoped working i dont know what happend i am using spatie laravel package to take db backup an i also have one other cron job in console and command
kernal.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\UpdateUserNotNew',
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
$schedule->command('cron:update-user-not-new')->everyMinute();
$schedule->command('backup:run')->everyMinute();
$schedule->command('backup:clean')->everyMinute();
}
/**
* Register the commands for the application.
*
* #return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}`
my issue is resolved byhttps://stackoverflow.com/a/65890784/14913109
only my php version was not integrated with php multimanager
The problem is most likely not coming from spatie/laravel-backup package. To run Laravels cronjob you need to a have a central call in your crontab to Laravels scheduler
* * * * * cd /path-to-your-project && php artisan schedule:run
You can also check all the scheduled tasks locally by running
$ php artisan schedule:work
and if they run fine locally then there is an issue with your server, but not with Laravel.
Also always have a look at storage/logs/laravel.log if there are any errors showing up.

laravel cron not firing but other crons are firing

I have a ubuntu 18.04 setup and running laravel 5.6 and i have set up the default scheduler in crontab -e
* * * * * php /var/www/html/laravel/artisan schedule:run >> /var/www/html/crons.txt 2>&1
and this is not running
my Kernel code
<?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\CompletelyReviewInternship',
'App\Console\Commands\MigrateUsers',
'App\Console\Commands\MigrateUsersTwo',
'App\Console\Commands\MigrateUsersThree',
'App\Console\Commands\MigrateUsersFour',
'App\Console\Commands\MigrateUsersFive',
'App\Console\Commands\MigrateUsersSix',
'App\Console\Commands\MigrateUsersSeven',
'App\Console\Commands\MigrateUsersEight',
'App\Console\Commands\MigrateUsersNine',
'App\Console\Commands\MigrateUsersTen'
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('review:internship')->hourly();
$schedule->command('migrate:users')->dailyAt('17:40');
$schedule->command('migrate:userstwo')->dailyAt('17:40');
$schedule->command('migrate:usersthree')->dailyAt('17:40');
$schedule->command('migrate:usersthree')->dailyAt('17:40');
$schedule->command('migrate:usersfour')->dailyAt('17:40');
$schedule->command('migrate:usersfive')->dailyAt('17:40');
$schedule->command('migrate:userssix')->dailyAt('17:40');
$schedule->command('migrate:usersseven')->dailyAt('17:40');
$schedule->command('migrate:userseight')->dailyAt('17:40');
$schedule->command('migrate:usersnine')->dailyAt('17:40');
$schedule->command('migrate:usersten')->dailyAt('17:40');
}
/**
* Register the commands for the application.
*
* #return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
Please Note :- my commands are firing with php artisan
and i am using nginx as my web server
any advise on this will be advisable
I think there might be multiple reasons of that:
Your application is in maintenance mode. In such case no command will be running unless you use ->evenInMaintenanceMode() for each command
You are using time, but time on your machine is different than what you expect so command will be run at some later point. Make sure time is really valid, or try to change time constraints to ->everyMinute() just to make sure it's not a problem in this case
As a side not - it' not necessary to list all command in $commands property if they are in Commands directory.
if you are using nginx then u have set user www-data in cron tab with super user permission like this
* * * * * sudo -u www-data php /var/www/html/laravel/artisan schedule:run >> /dev/null 2>&1

Laravel 5.4 - schedule:run works only once

I made a custom artisan command called db:dump which dumps my database into a sql file.
I tried applying it into a scheduler so it'll backup every time depending on the time range I want to apply. In this case, I tested it with everyMinute()
Here's what my Kernel look's like.
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 = [
Commands\MySqlDump::class,
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('db:dump')
->everyMinute();
}
/**
* Register the Closure based commands for the application.
*
* #return void
*/
protected function commands()
{
require base_path('routes/console.php');
}
}
It only works once when I execute php artisan schedule:run in my command prompt. Tried waiting for 5 minutes to see if it will backup 5 times but it didn't. I tried running schedule:run repeatedly and that's when it only worked each time. Basically speaking, it dumps an sql file every time I run schedule:run.
I'm totally lost now, advanced thanks to those who can help me. :)
You need to run cronjob on control panel plan servers like Plesk or directadmin or Cpanel.
egg:visit
If you are running locally, then you should use the following.
php artisan schedule:work
When you are on a live server, you have to set the cron configuration like the following
https://laravel.com/docs/8.x/scheduling#running-the-scheduler-locally

Resources