我的一个模型中有一个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.
您可以通过命令执行此操作,而不是调用函数。为那个cron作业命令,你可以在schedule
的kernel.php
方法中指定schdeuler
schedule->command('command Name')
->cron( \Carbon\Carbon::parse( $collection->expires_at )->format( 'i h d m' ) . ' *' );
希望这可以帮助 :)