【发布时间】:2017-08-30 09:45:57
【问题描述】:
我正在寻求帮助,我正在使用 RabbitMQ 的队列,我已经安装了 vladimir-yuldashev/laravel-queue-rabbitmq 并且一切正常,但最近我开始遇到一些错误,这真的很奇怪,因为它有时会发生。
它抛出
local.ERROR: 带有消息“explode() 的异常 'ErrorException' 期望参数 2 是字符串,给定数组”在 /home/ubuntu/workspace/frontend/vendor/laravel/framework/src/Illuminate/Queue/Jobs /Job.php:165,
我从Illuminate\Queue\Jobs\Job检查函数parseJob,并转储参数$job,有时它会收到一个类似Illuminate\Queue\CallQueuedHandler@call的字符串,但其他人会收到一个类似的实例
{
"__PHP_Incomplete_Class_Name":"App\\Jobs\\SendPost",
"log":[],
"post": {
"class":"App\\Models\\Post",
"id":72
},
"start":1491338912.0843,
"connection":null,
"queue":"front_send_post_0",
"delay":null
}
这是我的课:
namespace App\Jobs;
class CheckSendPost implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
const TOTAL_QUEUES = 3;
public function handle()
{
try {
$posts = Post::getRedyToPost(date('Y-m-d H:i'), null, 0);
$count = 0;
Log::info('front_check_send_post: ' . count($posts));
if (count($posts)) {
foreach($posts as $post) {
dispatch(
(new \App\Jobs\SendPost($post))
->onQueue('front_send_post_' . ($count%self::TOTAL_QUEUES))
);
$count++;
}
}
dispatch(
(new \App\Jobs\CheckSendPost)
->onQueue('front_check_send_post')
);
} catch (\Exception $e) {
Log::info('ERROR ' . $e->getCode() . ': ' . $e->getMessage());
}
}
}
namespace App\Jobs;
class SendPost implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
public $post = null;
public $start = null;
public function __construct(Post $post)
{
$this->post = $post;
$this->start = microtime(true);
}
public function handle()
{
Log::info('Post: '.$this->post->id);
try {
$this->post->publish();
$this->post->setSuccess();
} catch (\Exception $e) {
$this->post->setError();
} finally {
$this->post->save();
}
Log::info(
date('d-m-Y H:i:s').', '.
round((microtime(true) - $this->start), 4).' seg, '.
'Mem '.Helper::formatBytes(memory_get_usage()).', '.
'Max Mem '.Helper::formatBytes(memory_get_peak_usage())
);
}
}
并使用
- PHP 版本 5.6.29
- Apache/2.4.7 (Ubuntu)
- Laravel 5.3
感谢您的帮助。
【问题讨论】: