我有什么:
- 处理特定作业的流明服务
- Laravel 门户将文件发送到该服务以供其处理
一旦它只使用 JS 和 Ajax,它几乎可以正常工作——我唯一需要实现的是 CORS 中间件。但是,在我将逻辑移至 JWT(使用jwt-auth
包)和 GuzzleHttp(我正在使用它向服务 API 发送请求)之后,作业停止了通过数据库队列进行处理,而是像队列驱动程序设置为一样运行sync
。
以下是我在 API 调用期间调用的控制器:
public function processPackageById(Request $request) {
$id = $request->package_id;
$package = FilePackage::where('id', '=', $id)->where('package_status_id', '=', 1)->first();
if($package) {
Queue::push(new PackageProcessingJob(
$this->firm,
$this->accounts,
$package
));
return 'dispatching done for ' . $id;
}
return 'dispatching not done for ' . $id;
}
其中$this->firm
和$this->accounts
被注入特定模型的存储库。FilePackage
在 Laravel 站点上创建的对象,并且两者共享相同的数据库以使用。
结果没有工作被列入jobs
表格。当我使用 Postman 时,一切都很好。但是,当我尝试从 Laravel 后端发送请求时:
public function uploaderPost(Request $request)
{
// Here we get auth token and put into protected valiable `$this->token`
$this->authorizeApi();
$requestData = $request->except('_token');
$package = $requestData['file'];
$uploadPackageRequest =
$this->client->request('POST', config('bulk_api.url') .'/api/bulk/upload?token=' . $this->token,
[
'multipart' => [
[
'name' => 'file',
'contents' => fopen($package->getPathName(), 'r'),
'filename' => $package->getClientOriginalName(),
],
]
]);
$uploadPackageRequestJson = json_decode($uploadPackageRequest->getBody()->getContents());
$uploadPackageRequestStatus = $uploadPackageRequestJson->status;
if($uploadPackageRequestStatus == 1) {
$package = BulkUploadPackage::where('id', '=',$uploadPackageRequestJson->id)->first();
// If package is okay - running it
if($package !== null){
// Here where I expect job to be dispatched (code above)
$runPackageRequest =
$this->client->request('POST', config('api.url') .'/api/bulk/run?token=' . $this->token,
[
'multipart' => [
[
'name' => 'package_id',
'contents' => $package->id
],
]
]);
// Here I'm receiving stream for some reason
dd($runPackageRequest->getBody());
if($runPackageRequest->getStatusCode()==200){
return redirect(url('/success'));
}
}
}
return back();
}
谁能告诉我这里出了什么问题以及导致问题的原因?谢谢!