Search code examples
laravelcroncron-task

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


Solution

  • 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.