我向laravel作业中的服务发送有效负载以打印pdf。我正在使用artisan queue:work database
在本地运行作业,并且handle()
确实被调用,直到我使用Guzzle发送http请求的那一部分为止。
handle() {
try {
print_r("Assembling invoice data\n");
// ...
// ... doing some manual serialising
// ...
$client = new Client();
print_r("Sending pdf print job\n");
$response = $client->request("POST", $url, [
"json" => [
"sender_info" => $senderInfo,
"contact" => $contact,
"invoice_lines" => $invoiceLines,
"invoice_totals" => $invoiceTotals,
"invoice_footer" => $this->invoice->footer,
"invoice_note" => $this->invoice->note,
"invoice_meta" => [
"key" => $this->invoice->meta_key,
"value" => $this->invoice->meta_value
],
"invoice_date" => $this->invoice->date->format("d-m-Y"),
"invoice_due_date" => $this->invoice->due_date->format("d-m-Y"),
"invoice_color" => $this->invoice->color,
"invoice_number" => $this->invoice->number_prefix . $this->invoice->number_value,
"logo" => $this->invoice->logo,
"id" => $this->invoice->id
]
]);
print_r($response);
if ($response->getStatusCode() !== 200) {
print_r("pdf print job failed\n");
// @todo: send message to bugsnagger
throw new \Exception("Generating a pdf failed");
}
print_r("Pdf print job complete\n");
} catch (Exception $e) {
print_r($e);
}
}
我通过读取print_r()
语句验证了作业正在满足客户端的请求,但是没有完成。执行工作后,我只能看到的是
[2018-07-01 09:04:36] Processing: App\Jobs\ProcessNewInvoice
Assembling invoice data
Sending pdf print job
...仅需一秒钟即可完成255次。
首先,我使这段代码在Laravel作业之外运行。这似乎有效。不是超时之类的。现在,我很难弄清它在哪里失败了。有什么建议吗?
答案 0 :(得分:0)
原因完全无关。
"invoice_date" => $this->invoice->date->format("d-m-Y"),
"invoice_due_date" => $this->invoice->due_date->format("d-m-Y"),
模型上的日期属性未转换为Carbon对象,因此->format()
方法不存在。要在我的模型上修复日期转换,我必须将它们添加到Invoice.php;
protected $dates = [
"date",
"due_date",
];
仍然令我感到困惑的是,该作业没有引发异常,也没有被标记为失败。