我从未设置过排队系统。我决定给它一个镜头。看起来排队系统工作正常。但是,它似乎没有正确发送数据。这是我的代码。使用Laravel 4.1和Beanstalkd将数据传递给队列类
...
$comment = new Comment(Input::all());
$comment->user_id = $user->id;
$comment->save();
if ($comment->isSaved())
{
$voters = $comment->argument->voters->unique()->toArray();
Queue::push('Queues\NewComment',
[
'comment' => $comment->load('argument', 'user')->toArray(),
'voters' => $voters
]
);
return Response::json(['success' => true, 'comment' => $comment->load('user')->toArray()]);
}
...
处理这个看起来像这样的类:
class NewComment {
public function fire($job, $data)
{
$comment = $data['comment'];
$voters = $data['voters'];
Log::info($data);
foreach ($voters as $voter)
{
if ($voter['id'] != $comment['user_id'])
{
$mailer = new NewCommentMailer($voter, $comment);
$mailer->send();
}
}
$job->delete();
}
}
这精美的作品使用同步队列驾驶我的本地服务器上。但是,在我的生产服务器上,我使用Beanstalkd。队列正在按照预期发射。但是,我得到这样的错误:
[2013-12-19 10:25:02] production.ERROR: exception 'ErrorException' with message 'Undefined index: voters' in /var/www/mywebsite/app/queues/NewComment.php:10
如果我打印出来的$data
变量传递到NewComment
队列处理程序,我得到这样的:
[2013-12-19 10:28:05] production.INFO: {"comment":{"incrementing":true,"timestamps":true,"exists":true}} [] []
我不知道这是为什么发生。任何人都有一个想法如何解决这个问题。