6

laravel 什么时候执行它的任务调度的 yearly() 函数?是从第一次使用还是每年 01.01.YYYY 开始?

我检查了 laravel 文档和几页,但我无法找到这个问题的答案。

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

我希望它在 01.01.YYYY 上运行。

4

3 回答 3

5

Laravel 的年度事件对应 crontab 的年度事件。此处描述:

https://crontab.guru/every-year

于 2019-08-12T08:48:27.640 回答
4

这是产生的 cron:

0 0 1 1 *

哪个运行:

1 月第 1 天的 00:00。

于 2019-08-12T08:48:33.957 回答
3

年度函数定义在:

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

在这里您可以找到每日、每月和每年以及其他频率功能。

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);
}

正如在官方 Laravel 文档中所写的,daily 函数每天在午夜运行,因为 yearly 函数的定义方式与它在午夜 1/1/YYYY 运行的方式相同。

于 2019-08-12T09:15:27.357 回答