Laravel 9 Cron作业未运行

gc0ot86w  于 2023-03-09  发布在  其他
关注(0)|答案(1)|浏览(159)

我有一个Laravel 9项目。我需要通过Cron运行一些作业。根据文档,我已经更新了app/console/Kernel.php,如下所示(测试更新通知表):

namespace App\Console;

use App\Models\notification;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\DB;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')->hourly();

        $schedule->call(function () {
            $result = notification::where('id', 1)
               ->update(['read' => 1]);

            $notification = new notification([
                'client_id' => 3,
                'user_id' => 2,
                'client_post_id' => 750,
                'create_user_id' => 3,
                'notification' => '  System has created a notification'
            ]);

            $ok = $notification->save();
        })->everyMinute();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

当我运行php artisan schedule:list时,我确实看到cron作业正在运行:

Home@MacBook-Air cota % php artisan schedule:list       

* * * * *  Closure at: app/Console/Kernel.php:29 
 ............................................ Next Due: 42 seconds from now

但是,我没有看到数据库表中有任何变化(当我通过tinker在terminal中运行这些命令时,它工作正常,所以命令很好)
是否有任何我错过了或我需要配置的东西,使写入数据库通过Cron作业。
另外,在哪里可以看到cron错误?

bjp0bcyl

bjp0bcyl1#

你可使用
php工匠时间表:工作
Artisan命令。此命令将在前台运行,并每分钟调用一次调度程序,直到您终止此命令

相关问题