【问题标题】:Run scheduler using cron method in Laravel在 Laravel 中使用 cron 方法运行调度程序
【发布时间】:2019-09-06 04:15:23
【问题描述】:

我的一个模型中有一个expires_at 列,我想根据它的时间戳运行一个调度程序。

我尝试了以下代码:

$collection = Foo::first();
$schedule->call( function() {
    // Do Something
})->cron( \Carbon\Carbon::parse( $collection->expires_at )->format( 'i h d m' ) . ' *' );

但是当我在过期日期运行php artisan schedule:run 时,我得到No scheduled commands are ready to run.

【问题讨论】:

    标签: laravel cron scheduler


    【解决方案1】:

    您可以通过命令来代替调用函数。为该cron作业创建命令,然后您可以在schedulekernel.php的方法中指定该schdeuler

    schedule->command('command Name')
            ->cron( \Carbon\Carbon::parse( $collection->expires_at )->format( 'i h d m' ) . ' *' );
    

    希望这会有所帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-18
      • 1970-01-01
      • 2021-05-14
      • 2017-03-31
      • 2019-04-18
      • 1970-01-01
      • 1970-01-01
      • 2013-09-26
      相关资源
      最近更新 更多