Mws*_*LLC 2 laravel laravel-5 laravel-5.7
嗨,很抱歉给您带来麻烦,我在创建计划命令时遇到了这个问题。
在我们的 crontab -e 用户中,我们在 Debian 上插入了以下内容:
* * * * * cd /var/www/myfolder.com/ && php artisan schedule:run >> crontab.laravel
我们已经正确输入了日程功能,如下所示:
应用程序/控制台/kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
// 'App\Console\Commands\HelpCenter',
Commands\HelpCenter::class
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('elena:help')->everyMinute();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__ . '/Commands');
require base_path('routes/console.php');
}
}
Run Code Online (Sandbox Code Playgroud)
但结果仍然是没有准备好运行的预定命令 我们尝试了所有不可能的组合,但没有。如果我们取消对函数 Artisan call working 的注释,脚本将被执行
尝试强制命令 crontab -e
为了更好地了解问题出在哪里,我们直接使用命令添加了一个 crontab,而无需经过计划,如下所示:
* * * * * cd /var/www/myfolder.com/ && php artisan elena:help >> crontab.laravel
这个命令每分钟都完美运行,所以我们无法弄清楚问题出在哪里。如果您有耐心给我们一些建议,我们会很高兴。再会
我在这里复制这个,因为这解决了我的问题。这是上面的@piscator 评论。
“您运行了php artisan cache:clear吗?您的存储/框架文件夹中可能缓存了一个计划文件。”
编辑:
这个问题给我带来了很多麻烦。我正在使用 Laravel 5.8,但无法使用->withoutOverlapping(); 该任务将在没有明显原因的情况下结束一段时间,然后 cron 作业无法再次启动它,因为->withoutOverlapping()它阻止了它。
最后我在这里找到了解决方案:
基本上,不是使用 Laravel 的->withoutOverlapping(),而是检查自己是否已在运行任务。
// start the queue worker, if its not running
$command = "queue:work --queue=high,email,default,low --tries=3 --delay=3";
if (!$this->osProcessIsRunning($command)) {
$schedule->command($command)->everyMinute()
->runInBackground()
->appendOutputTo(storage_path('logs/queue.log'));
}
// function for checking if the task is running
protected function osProcessIsRunning($needle)
{
// get process status. the "-ww"-option is important to get the full output!
exec('ps aux -ww', $process_status);
// search $needle in process status
$result = array_filter($process_status, function($var) use ($needle) {
return strpos($var, $needle);
});
// if the result is not empty, the needle exists in running processes
if (!empty($result)) {
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
感谢@henryonsoftware提供的解决方案
| 归档时间: |
|
| 查看次数: |
3975 次 |
| 最近记录: |