6

When is laravel executing the yearly() function of it's task scheduling? Is it from the first time it was used or is it each year on 01.01.YYYY?

I checked up the laravel docs and several pages, but I wasn't able to find out the answer to this question.

$schedule->call(function () {
  DB::table("invoice_settings")
    ->where("key", "invoice_number")
    ->update(["value" => 860001]);
  })->yearly();

I expect that it's running on the 01.01.YYYY.

Commander
  • 264
  • 2
  • 12

3 Answers3

5

Laravel's yearly coresponds to crontab's yearly event. Described here:

https://crontab.guru/every-year

4

This is the cron produced:

0 0 1 1 *

Which runs:

At 00:00 on day-of-month 1 in January.

nakov
  • 13,938
  • 12
  • 60
  • 110
3

The yearly function is defined in:

vendor/laravel/framework/src/Illuminate/Console/Scheduling/ManagesFrequencies.php

Here you can find the daily, monthly and yearly, and other frequency functions.

public function daily()
{
    return $this->spliceIntoPosition(1, 0)
                ->spliceIntoPosition(2, 0);
}

public function monthly()
{
    return $this->spliceIntoPosition(1, 0)
                ->spliceIntoPosition(2, 0)
                ->spliceIntoPosition(3, 1);
}

public function yearly()
{
    return $this->spliceIntoPosition(1, 0)
                ->spliceIntoPosition(2, 0)
                ->spliceIntoPosition(3, 1)
                ->spliceIntoPosition(4, 1);
}

As in the official Laravel documentation is written that the daily function runs daily at midnight, since the yearly function is defined in the same way it will run at the 1/1/YYYY at midnight.

Davide Casiraghi
  • 15,591
  • 9
  • 34
  • 56