2

I'm puzzled by a weird Laravel 5 behaviour. I added this to the \app\Console\Kernel.php:

protected function schedule(Schedule $schedule)
{
    //$schedule->command('inspire')->hourly();
    $schedule->command(Utilsclass::log_line("CROM JOB EXECUTED @ ".date('l jS \of F Y h:i:s A')))->monthly();
}

and I expect to see an activity on my log once a month, but this is what I get on log.txt:

CROM JOB EXECUTED @ Tuesday 29th of December 2015 03:32:01 PM

CROM JOB EXECUTED @ Tuesday 29th of December 2015 03:33:01 PM

CROM JOB EXECUTED @ Tuesday 29th of December 2015 03:34:01 PM

CROM JOB EXECUTED @ Tuesday 29th of December 2015 03:35:01 PM

CROM JOB EXECUTED @ Tuesday 29th of December 2015 03:36:01 PM

CROM JOB EXECUTED @ Tuesday 29th of December 2015 03:37:01 PM

CROM JOB EXECUTED @ Tuesday 29th of December 2015 03:38:02 PM

CROM JOB EXECUTED @ Tuesday 29th of December 2015 03:39:01 PM

CROM JOB EXECUTED @ Tuesday 29th of December 2015 03:40:01 PM

so every minute, regardless of the method used. In fact using daily() or hourly() makes no difference at all.

Besides being quite new to Laravel I don't know how to hunt down a problem, which seems something like a bug to me...

Any help?

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
KONEY
  • 73
  • 6
  • The `Utilsclass::log_line(...)` expression gets evaluated every time the code is executed because its results needs to be passed to the `command` method (which expects a string parameter with the command name and any passed parameters, as you would call it from the CLI but without the `php artisan` part). You should use `call` and a closure as @Marcin Nabiałek suggests in his answer. – Bogdan Dec 29 '15 at 16:02

1 Answers1

1

You should use closure for that to execute this code daily and not for each cron execution:

$schedule->call(function () {
            Utilsclass::log_line("CROM JOB EXECUTED @ ".date('l jS \of F Y h:i:s A'));
        })->daily();
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • The docs don't mention this at all and the provided example makes no sense as well. This works very well. thanks. – KONEY Jan 07 '16 at 08:20