I am looking for help, I am using queues with RabbitMQ, I have installed vladimir-yuldashev/laravel-queue-rabbitmq
and all ok, but recently I started to get some errors, It's really odd because it just happen sometimes.
It throws
local.ERROR: exception 'ErrorException' with message 'explode() expects parameter 2 to be string, array given' in /home/ubuntu/workspace/frontend/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php:165,
I check the function parseJob from Illuminate\Queue\Jobs\Job
, and dump the parameter $job
, sometimes it receives a string like Illuminate\Queue\CallQueuedHandler@call
, but others receives an instance like
{
"__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
}
this are my classes:
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())
);
}
}
and using
- PHP Version 5.6.29
- Apache/2.4.7 (Ubuntu)
- Laravel 5.3
Thanks for your helps.