Reputation: 1074
I'm setting up the Queue in L4 for the first time and i encountered some problems. I have i simple controller method like this:
public function getIndex()
{
$data = array(
'offset' => 3300000,
'site' => 1
);
Queue::push('Class@jobmethod', $data);
return 'OK!';
}
At the bottom of the job method, i do something like this:
public function jobmethod()
{
....
$data = array(
'offset' => $data['offset'] + 100,
'site' => $data['site']
);
Queue::push('Class@jobmethod', $data);
$job->delete();
}
So the job loops through the queue once again with a higher offset. Now my problem is that when i call the controller method in my browser, it will never return OK!, but just keep loading the page? I set the job up to log in a DB table and i can see that it keeps running several times.
Does anyone have an idea on whats going on here?
Upvotes: 1
Views: 4933
Reputation: 1071
I think that you are going into a infinite recursion
public function getIndex()
{
$data = array(
'offset' => 3300000,
'site' => 1
);
Queue::push('Class@jobmethod', $data); //Here you push the job to the queue
return 'OK!';
}
public function jobmethod()
{
....
$data = array(
'offset' => $data['offset'] + 100,
'site' => $data['site']
);
Queue::push('Class@jobmethod', $data); //This is creating infinite recursion!!!
$job->delete();
}
consider this variant:
public function getIndex()
{
$data = array(
'offset' => 3300000,
'site' => 1
);
Queue::push('Class@jobmethod', $data); //Here you push the job to the queue
return 'OK!';
}
public function jobmethod($data)
{
....
//Queue::push('Class@jobmethod', $data); //This is creating infinite recursion!!!
$job->delete();
}
Upvotes: 3
Reputation: 1886
I guess you have your default queue handler set as "sync". You can check this in app/config/queue.php.
What this does is directly process the event, because there's no actual queue installed.
So in your case, it will constantly run the jobmethod, because it keeps iterating over the same function. If you remove the Queue push in the jobmethod, it will return OK.
So to make this work, you have to install a queuing system like Beanstalkd. If you do this, make sure you add "pda/pheanstalk": "dev-master"
in the require section of your composer.json.
If you want to run the queue, check my answer for this question: How to fire Laravel Queues with beanstalkd
Upvotes: 9