0

I have beanstalkd setup. I'm using the pheanstalk php library for adding jobs and for my workers.

Adding jobs is working correctly and I am logging the job id's in my database for later reference. No job id's are being skipped IE: they go in there sequentially numbered: 1,2,3,4

Now the part thats sort of working is the workers. They are working in the fact that they do what there supposed to but I have three of them running and for some reason the same job gets run two or three times rather than just once.

I'm not sure why this would be happening I am simply using a while loop with a memory check + my job code to monitor for a new job.

Here is the start of that code.

    while (1) {
        $job = $this->pheanstalk->watch('my_tube')->ignore('default')->reserve();
        $job_decoded = json_decode($job->getData(), false);

Here is the output from benstalk console. Ignore the first line as that is the default tube which I am not using.

enter image description here

After adding one more job to the queue the total column incresses to 4 and nothing else changes.

Alister Bulman
  • 34,482
  • 9
  • 71
  • 110
hcker2000
  • 603
  • 1
  • 6
  • 30

1 Answers1

1

I found out the issue was an error causing the first worker to do what it was supposed to do but then crashing before removing the job.

So the next worker would pick it up and it would fail jumping to my catch block and bypassing the php error and then delete the job.

hcker2000
  • 603
  • 1
  • 6
  • 30
  • This is one of the main problems you have to solve when using queues and workers - if they fail, you have to catch it, and do the right thing - ignoring the error and just retrying is rarely correct - it's just going to fail next time as well, and then you are in an infinite loop. Verbose logging can help a lot to help figure out what is going on. – Alister Bulman Jan 06 '14 at 11:07
  • Hey hcker nice, question and answer. I am starting to use pheanstalk and have a few doubts myself. I created a question, might you be able to give me your insight on it? http://stackoverflow.com/questions/37370688/pheanstalk-and-beanstalk-functions – Webeng May 22 '16 at 19:43