Php Laravel worker没有尝试该作业,而是将其删除

Php Laravel worker没有尝试该作业,而是将其删除,php,laravel,queue,supervisord,Php,Laravel,Queue,Supervisord,拉威尔5.4 php7.1.32 主管3.3.1 (我知道……我知道。这家公司落后了3年) config/queue.php 'database' => [ 'driver' => 'database', 'connection' => 'queue', // means in config/database.php I have to setup a new connection 'table' => 'jobs', 'queue'

拉威尔5.4
php7.1.32
主管3.3.1
(我知道……我知道。这家公司落后了3年)

config/queue.php

'database' => [
    'driver' => 'database',
    'connection' => 'queue', // means in config/database.php I have to setup a new connection
    'table' => 'jobs',
    'queue' => 'default',
    'retry_after' => 90,
],
管理器配置

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/project/artisan queue:work
autostart=true
autorestart=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/html/project/storage/logs/supervisord.log

场景:调度队列时,会将新行添加到作业表中。然后将一个Laravel Worker分配给一个作业,此时将更新保留的_at&truments列。作业完成后,该行(作业)将被删除

现在,由于一些神秘的原因,有时一个作业可以无缝地工作&有时一个作业在那里但没有分配给它的工人,并且在一瞬间该作业被删除。刚才发生了什么?而且,这是如此的断断续续,以至于很难跟踪哪些作业实际上被尝试过,后来被删除了,或者只是因为这个问题而被删除了

我已经挠头至少一个星期了,请引导我


编辑
-
php artisan队列:重新启动
broadcast,主管会更新更新启动时间,但问题没有改善。
-后来,我删除了主管,并尝试使用手动方式
php artisan queue:work
,甚至也删除了作业,而不是尝试它(也没有在失败的作业中插入新数据)


编辑(2)-日志 以下是分派作业的函数

public static function sendVoiceCall($instituteSmsSettings, $announcementId, $postUrl, $mobileNumbers)
    {
        Log::debug('Job dispatched');
        dispatch(new SendVoiceCall($instituteSmsSettings, $announcementId, $postUrl, $mobileNumbers));
    }
这是工作

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;

class SendVoiceCall implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $tries = 3;
    protected $ARR_POST_DATA = array();
    protected $postUrl = '';

    public function __construct($instituteSmsSettings, $announcementId, $postUrl, $mobileNumbers)
    {
        $this->ARR_POST_DATA['username'] = $instituteSmsSettings->username;
        $this->ARR_POST_DATA['token'] = $instituteSmsSettings->token;
        $this->ARR_POST_DATA['announcement_id'] = $announcementId;
        $this->ARR_POST_DATA['plan_id'] = $instituteSmsSettings->plan_id;
        $this->ARR_POST_DATA['caller_id'] = $instituteSmsSettings->caller_id;
        $this->ARR_POST_DATA['contact_numbers'] = $mobileNumbers;
        $this->postUrl = $postUrl;
    }

    public function handle()
    {
        Log::debug('Job started');
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $this->postUrl);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($this->ARR_POST_DATA));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

        $sendCallResponse = curl_exec($curl);
        $curlResponse = json_decode($sendCallResponse, true);
        curl_close($curl);

        Log::info('Queue complete. Announcement Id: ' . ($this->ARR_POST_DATA['announcement_id'] ?? ''));
    }
}

如您所见,队列同时启动和完成(应该有2-3秒的差异。工作人员正在删除作业,而不是尝试它。

您的作业正在发出一个curl请求,但没有错误处理或检查该调用。请求可能由于某种原因失败,但此作业永远不会告诉您。尤其是现在,当出现无法解释的问题时,它会有意义e对请求和响应执行一些基本的错误检查

你可以检查几件事。一旦你解决了这个特定的问题,可能不需要做所有这些,但是你应该至少使用其中一件来跟踪这个电话

  • 用于检查呼叫是否有效

  • 用于向您显示网络请求和响应的详细信息。这将为您提供大量信息,包括
    http\u响应
    ,您可以测试它是否为
    200
    或您期望的任何内容

  • 如果远程服务器响应某个消息-可能是因为您正在
    json\u decode()
    ing它-记录它。如果响应中存在某种成功/失败元素,请测试它,确保它是您期望的

例如(如前所述,您通常不会执行所有这些操作,只需选择适合您的情况的操作):


您是否有failed_jobs表?如果是,它是否会被这些丢失的作业填充?是否存在代码本身产生的错误以某种方式被吞没的情况,例如被try-catch块吞没,其中catch不起任何作用?@GeorgeKoniaris failed_jobs表为空,即使丢失的作业被删除。我已添加try-catch块我还添加了用于调试的日志,但代码在dispatch()之后运行良好代码添加到作业表中。主管日志中也没有抛出错误。您能否尝试禁用
自动重新启动
并再次执行它?我很好奇为什么您的
失败的\u作业
表和主管日志文件中都没有日志记录。我的第一个猜测是SEGFULT问题。这种情况很少发生在我身上,但遗憾的是,这种情况时常发生到时间。特别是因为您使用的是带有PHP7+的旧L5版本。您是否能够使用准确的PHP版本在本地复制它?您应该将日志添加到作业类中,以查看发生了什么。只需重复已经提出的建议,因为您在这里还没有明确地排除它-最简单的解释是,该作业实际上不存在n、 不会产生任何输出或任何错误,并正常完成。您100%确定不会发生这种情况吗?添加日志记录作为代码执行的第一件事,这样您就可以查看它是否启动。我注意到的一件事是,您有
user=root
,这通常是您的web服务器运行时的用户,root是否真的正确?可能有一些错误在某些情况下,输出文件或日志被创建为根目录,导致以后的写入问题?你是对的。响应中有一个curl错误。感谢@Don’t Panic指导我并帮助我理解请求和响应的基本错误检查。赏金是你的。谢谢。
[2020-04-13 10:17:49] production.DEBUG: Job dispatched  
[2020-04-13 10:17:50] production.DEBUG: Job started  
[2020-04-13 10:17:50] production.INFO: Queue complete. Announcement Id: 203691 
$curl = curl_init();
// ... your code

// Get request info as an array
$info = curl_getinfo($curl);

$sendCallResponse = curl_exec($curl);
curl_close($curl);

// Log the actual response from the remote server
Log:info('Curl response: ' . $sendCallResponse);

// Log extensive info about the request/response, good when troubleshooting
Log:info('Curl info: ' . print_r($info, true));

// Maybe check the http response code
if ($info['http_code'] !== 200) {
    // handle an error, send a notification, etc
    Log:info('Whoah, remote server responded with ' . $info['http_code']);
}

// Maybe check if curl returned an error
if ($sendCallResponse === false) {
    // handle an error, send a notification, etc
    Log:info('Oh noes, curl error! ' . curl_error($curl));
}

// Maybe test the actual response, if there is something testable in it, 
// say a "status":
if ($curlResponse['status'] !== 'OK') {
    // handle an error, send a notification, etc
    Log:info('Remote returned status ' . $curlResponse['status']);
}