Trying to do task scheduling but not working properly. I set the time and wrote the commands but not running.
Here is my commands;
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\allestates;
protected $signature = 'bot:mitsui';
Also my Kernel is here:
protected $commands = [
//
Commands\mitsui::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('bot:mitsui')->everyFiveMinutes();
}
What am I missing here? Thanks for helping me out!
Are you running the schedule cron.? You need to add this into your cpanel crons or cronjob.
php {project_path}/artisan schedule:run > /dev/null 2>&1
If not add the above command to your cron jobs and run it everyminute.
Here the steps if you have root access,
crontab -e
//Add follow line to crontab
* * * * * php {project_path}/artisan schedule:run >> /dev/null 2>&1
I have deployed laravel 5.4 app in AWS Ubuntu 16.04 apache2, i have created task scheduler for sending emails dailyAt('10:00').
When i run the artisan command php artisan email:reminder manually every thing works fine.
But when i run php artisan schedule:run i am getting No scheduled commands are ready to run.
I have also ran * * * * * php /var/www/html/app/artisan schedule:run >> /dev/null 2>&1 referring to documentation.
This is Kernal.php
class Kernel extends ConsoleKernel
{
protected $commands = [
\App\Console\Commands\EmailReminder::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('email:reminder --force')->dailyAt('10:00');
}
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
Your schedule will only work if you call it at 10:00,
add this cronjob
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
Laravel will call this function everyminute, and once it is 10:00 it will call the function accordingly.
Check https://laravel.com/docs/5.5/scheduling#introduction , search for 'Starting The Scheduler'
In AWS ECS we can use this without adding cron in to the container
https://github.com/spatie/laravel-cronless-schedule
php artisan schedule:run-cronless
I am setting cron job first time in Laravel 5.2. As per their docs, I have modified my app/Console/Kernel.php as -
protected $commands = [
\App\Console\Commands\Inspire::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->call(function() {
$myfile = fopen("testfile.txt", "w");
}
)->everyMinute();
}
And start scheduler -
* * * * * php /var/www/html/{project_dir}/artisan schedule:run 1>> /dev/null 2>&1
I want to run this cron every minute. But it is totally not working.
If I tried with php artisan schedule:run cron runs and "testfile.txt" generated in root folder. But why it is not calling automatically every minute? I don't know what's going wrong here.
Any help is appreciated.
Thanks.
The below is the schedule function
protected function schedule(Schedule $schedule)
{
$schedule->command('queue:work')
->everyMinute()
->withoutOverlapping();
}
Below is the cron for laravel
* * * * * /usr/local/bin/php /home/space/public_html/project/artisan schedule:run >> /home/space/public_html/project/public/op.txt 2>&1
But each time the cron outputs
No scheduled commands are ready to run.
queue:work is not getting executed, what am I doing wrong?
Deleting all the schedule files in storage/framework did this job.
The problem was the command was executed but was some error so never worked but the command was active preventing it to run again by the cron (because i used withoutOverlapping() ).
My laravel version is 5.0.28, I build on cloud9, and 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
I added this code on my Kernel.php. I referenced this site: 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 waited and it still didn't work, so I tried to use the command php artisan schedule:run, and I got: No scheduled commands are ready to run.
I searched and found this answer: Laravel 5 "Class does not exist" when using the scheduler
So I modified my code. Also, this code had no specified time, so I modified my cron to specify a time, but it still doesn't work. I have no more ideas. please help. Thanks.
code
$schedule->call(join('#', [ApiController::class, 'test_job']));
cron
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
first to Test if cron is running in your server or localhost type:
> sudo service cron status
if not installed:
> sudo apt-get install cron
to enable laravel's scheduler:
> crontab -e
and you can select an editor if not vim opens directly. Be sure to enter there this line at the bottom:
* * * * * php /path_from_root_to_laravel_proj_folder/artisan schedule:run 1>> /dev/null 2>&1
to Test if you have setup inside laravel the scheduler right, run this from your projects folder:
>php artisan schedule:run
this should execute the tasks and tell you what is doing.
Laravel scheduler works with commands, not with controller methods:
create command:
php artisan make:command PurchasePodcast
edit command:
namespace App\Console\Commands;
use Illuminate\Console\Command;
class PurchasePodcast extends Command
{
protected $name = 'purchase:podcast';
public function fire()
{
// do stuff here
}
}
add command to Console\Kernel.php:
protected $commands = [
'App\Console\Commands\PurchasePodcast',
];
use command in scheduler:
$schedule->command('purchase:podcast')->hourly();
In my case, the scheduler actually run but encountered an error because of lower php version, beside artisan path (which is your project folder), I had to set the php path as below:
* * * * * /path_to_php_folder/bin/php /path_from_root_to_laravel_proj_folder/artisan schedule:run 1>> /dev/null 2>&1
There are several aspects to find the cause:
First, check whether the 'timezone' in config/app.php is set properly. Laravel will reset the timezone even though you already configured it in php.ini.
Secondly, check that crontab is working as expected. When you get the message "No schedule to be ready", it means your crontab is running and can detect the php and artisan command.
In order to complete #limonte's answer the create Console Command is the following:
php artisan make:console CampaignsCollect --command=campaigns:collect
Reference here: link