Reputation: 922
I'm having an issue with Laravel's scheduler. It's setup properly, the command is correct as I can run it from the terminal, but it doesn't work at all. The CRON job is correct as far as I know as it does show up with sudo service cron status
But php artisan schedule:run
says nothing is queued. My Kernel.php is as follows
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
'App\Console\Commands\ResetBars',
'App\Console\Commands\ResetUsers',
'App\Console\Commands\UpdateBars',
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('reset:bars')->hourlyAt(1);
$schedule->command('reset:users')->daily();
//$schedule->command('update:bars')->dailyAt('8:00');
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
I have a slack log at the end of the command (which I've verified works) and it isn't sending anything hourlyAt(1) so it should've JUST ran at 8:01 but it didn't.
Anyone have any thoughts on why it isn't running? Is it getting queued and just not running?
This is in the cron tab
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* * * * * php ~/var/www/BarhopAPI/artisan schedule:run >> /dev/null 2>&1
Thanks
Upvotes: 1
Views: 6491
Reputation: 409
I got the same issue while setting a CRON job
I was using "dailyAt()" to run the CRON, Actually, my CRON was running but the timezone is not own mine. Please go and check your "config/app.php" and check your timezone (I just changed my timezone to 'Asia/Kolkata')
To test your CRON please comment the scheduler inside your schedule() method and add a new schedule (This step will help you to check your CRON is working or not )
$schedule->command('jobexp:warning')->cron('* * * * *');
php artisan schedule:run
Please ensure that your CRON is working
Upvotes: 0
Reputation: 922
Okay so the steps I followed to make sure I did it right
crontab -l
from @devk, thank you so much for that
To add a crontab job to your Laravel install it's crontab -e
, then when prompted for what type (if your first time setting it up) hit 2
to go to nano, then paste the following after the asterisks
* * * * * php /var/www/Laravel/artisan schedule:run >> /dev/null 2>&1
Obviously replacing the /var/www/Laravel
with the path to your Laravel install
Edit: That did not work.
Edit2: @devk helped me fix it, needed to remove the ~
Upvotes: 2