When is laravel executing the yearly() function
Asked Answered
V

3

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.

Vapor answered 12/8, 2019 at 8:42 Comment(1)
it's indeed yearly starting 01.01.YYYYRhaetia
L
5

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

https://crontab.guru/every-year

Legalese answered 12/8, 2019 at 8:48 Comment(0)
N
4

This is the cron produced:

0 0 1 1 *

Which runs:

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

Nonalignment answered 12/8, 2019 at 8:48 Comment(0)
B
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.

Baum answered 12/8, 2019 at 9:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.