首页 > 解决方案 > Cron 作业无法使用 Nanobox 处理 Lumen

问题描述

我正在尝试在 nanobox 中编写 cron 作业。我在 Kernel.php 中实现了一些逻辑,并在 boxfile.yml 文件中进行了相应的更改。在此之后,我的预定作业预计每小时运行一次,但它没有运行。我不知道我在这里错过了什么。

我的 boxfile.yml 的相关部分如下所示

  cron:
    - id: scheduleForRSS
      schedule: '0 * * * *'
      command: 'php artisan schedule:run'

我的 Kernel.php 文件有以下类

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function () {
            //DB::table('keyword')->delete();
            echo "Hello, from Kernel.schedule !";
            DB::table('xyz')->insert([
                ['title' => 'abc', 'value' => 0]            
            ]);
        })->everyMinute();
    }
}

然而,当我运行以下命令时,调度函数被调用,我可以在控制台上看到输出以及一条记录被插入到数据库中,证明该函数已正确实现并执行它应该做的事情。就是这样,由于某种原因,它没有被 nanobox 的 cron 作业功能调用。

/app $ *php artisan schedule:run*

Running scheduled command: Closure
Hello, from Kernel.schedule !

标签: laravelcronschedulerlumen

解决方案


搞定了,cron-jobs 不在本地机器上运行。当我将它部署在服务器(在我的情况下为 aws)上时,作业开始运行。


推荐阅读