1

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?

asked Jul 3, 2013 at 9:21

2 Answers 2

9

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

answered Jul 3, 2013 at 9:51
0
3

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();
 }
answered Sep 11, 2014 at 15:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.