php - 有没有办法检查 Laravel 计划是否正在运行?
问题描述
我在不同的主机上维护一个应用程序(基于 Laravel 构建)的多个副本,并且我正在寻找一种方法来检查 Laravel Schedule 是否真的为每个应用程序运行。Laravel 是否为此提供了一些东西?
解决方案
我有同样的问题,并通过在我的命令中使用一个选项来修复它:
class SomeCommand extends Command
{
protected $signature = 'some:command {--other-option} {--schedule}';
public function handle()
{
if ($this->option('schedule')) {
// this command is triggered by the schedule
}
}
}
在你的app/Console/Kernel.php
:
class Kernel extends ConsoleKernel
{
/**
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*/
protected function schedule(Schedule $schedule)
{
$schedule->command(SomeCommand::class, ['--schedule'])->hourly();
}
protected function commands()
{
$this->load(__DIR__ . '/Commands');
}
}
推荐阅读
- android - 在 Flutter 中显示列表中的一个元素
- ruby-on-rails - Rails ActionView::SyntaxErrorInTemplate(渲染模板时遇到语法错误:)
- ssl - 如何为 Google Cloud 负载均衡器设置 Letsencrypt?
- json - 使用 Spring Batch 生成非常大的复杂 JSON 文件
- reactjs - 如何使用 useContext 钩子传递数据?
- apache-kafka - Confluent Replicator 的偏移转换如何处理时钟偏差?
- html - 如何根据屏幕大小对齐项目?
- excel - 发送附件 PDF
- python - Python NameError:未定义名称'timeInMinutes'
- javascript - chrome 扩展 java 脚本中是否有与 selenium FindElements By.XPath 等价的东西?