laravel task scheduler

Ad

I want to know if the task scheduler of laravel forge override the settings in my Kernel Class file because I don't understand which one it will use because I set in the dashboard of laravel forge daily and in my kernel class file a command to run only it's the first of the month like this

$schedule->command('log:demo')->daily()->when(function(){
            if(Carbon::now()->toDateString() == Carbon::now()->startOfMonth()->toDateString())
            {
                return true;
            }
});

I put daily() function here to check everyday if it's the first of the month and I know that it will not be executed if the function doesn't return true but with laravel forge it's executed everyday , I think forge doesn't look at this file enter image description here

Ad

Answer

Ad

You want the schedule:run to run EVERY MINUTE - this checks what you have in your Kernel and if something needs to be ran on that minute it will run that particular task (job).

For example if I have a task that runs once per/hour and another that runs once per day. I would only need ONE scheduled task in Forge: schedule:run - THEN in my Kernel I would have

protected function schedule(Schedule $schedule)
{
     $schedule->command('report:hourly')->hourly();
     $schedule->command('report:daily')->daily();
}

Make sure that your commands are registered with the Kernel:

 protected $commands = [
     Commands\Hourly::class,
     Commands\Daily::class,
];
Ad
source: stackoverflow.com
Ad