Laravel工作人员没有尝试该工作,而是删除了它



laravel5.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


SCENARIO:调度队列时,会向作业表中添加新行。然后将Laravel Worker分配给作业,此时reserved_at&尝试列被更新。作业完成后,行(作业(将被删除。

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

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


编辑
-php artisan queue:restart广播,主管会更新更新时间,但问题没有改善
-后来,我删除了主管,并尝试手动操作php artisan queue:work,甚至删除了作业,而不是尝试(failed_jobs中也没有插入新数据(。


编辑(2(-日志
以下是调度作业的功能

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

这是作业

<?php
namespace AppJobs;
use IlluminateBusQueueable;
use IlluminateQueueSerializesModels;
use IlluminateQueueInteractsWithQueue;
use IlluminateContractsQueueShouldQueue;
use IlluminateFoundationBusDispatchable;
use IlluminateSupportFacadesLog;
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'] ?? ''));
}
}

这是日志

[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 

正如您所看到的,队列同时开始和结束(应该有2-3秒的差异。工作人员正在删除作业,而不是尝试它

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

你可以检查一些东西。一旦你解决了这个特定的问题,可能就不需要做所有这些,但你可能应该至少使用其中一个来监视这个调用。

  • 使用curl_error()检查调用是否有效;

  • 使用curl_getinfo()向您显示网络请求和响应的详细信息。这会给你很多信息,包括http_response,你可以测试它是200或任何你期望的;

  • 如果远程服务器以某种消息进行响应(可能是因为您正在json_decode()处理它(,请将其记录下来。如果响应中存在某种成功/失败元素,请对其进行测试,确保它符合您的预期;

例如(如前所述,你通常不会做所有这些,只需选择适合你的情况(:

$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']);
}

最新更新