在Laravel中使用cron方法运行调度程序

问题描述 投票:0回答:1

我的一个模型中有一个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个回答
0
投票

您可以通过命令执行此操作,而不是调用函数。为那个cron作业命令,你可以在schedulekernel.php方法中指定schdeuler

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

希望这可以帮助 :)

© www.soinside.com 2019 - 2024. All rights reserved.