Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is laravel executing the yearly() function

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.

like image 663
Commander Avatar asked Aug 12 '19 08:08

Commander


Video Answer


3 Answers

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

https://crontab.guru/every-year

like image 183
ethris Avatar answered Nov 30 '22 23:11

ethris


This is the cron produced:

0 0 1 1 *

Which runs:

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

like image 28
nakov Avatar answered Nov 30 '22 23:11

nakov


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.

like image 27
Davide Casiraghi Avatar answered Dec 01 '22 00:12

Davide Casiraghi