laravel - 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 !
解决方案
搞定了,cron-jobs 不在本地机器上运行。当我将它部署在服务器(在我的情况下为 aws)上时,作业开始运行。
推荐阅读
- python - 我想多线程一行代码,但代码不能在 def 中运行
- c# - 如何保持类实例活着?
- python - 使用 __slots__ 有什么缺点吗?
- sql-server - 插入表时死锁 MS-SQL
- javascript - 如何覆盖已标记为 !important 的内联 CSS 从外部 HTML
- python - 有没有办法缩短我的代码,这样我就不用写“乌龟”了。每次我使用turtle模块中的函数?
- java - 我需要帮助将 Spring MVC 中的 MultipartFile 保存到 SMB 网络驱动器
- excel - 如何删除带有选定文本的行?
- angular - 如何从 $event 获取角度项目?
- javascript - 如何从javascript中选择数据属性