Question

I'm intermediate in Beanstalk + Pheanstalk. I'm developing my core part (background process) using Beanstalk. It's excellent tool that's no doubt but I'm stuck in one situation. I'm using beanstalk using Yii framework.

Let's say, I have two jobs A (Tube - A-Jobs) and B (Tube - B-Jobs) and both are under different tube and workers. B is dependent on A. It may possible that B will fetch first by worker before A and will start process on it. In that case, I need B to delay for some seconds (120 secs) untill A will execute.

As per my knowledge, there isn't any direct way to make job delay. For this you need to delete job B and put back to same queue with delay time. Correct me if I'm wrong here.

Now situation is that, I'm not able to get actual tube name in that case, because pheanstalk only providing Job Id and Job Data. I'm pasting you my code below,

$pheanstalkA = Yii::app()->beanstalk->getClient($client);
$pheanstalkA->watch('A-tube');

$pheanstalkB = Yii::app()->beanstalk->getClient($client);
$pheanstalkB->watch('B-tube');

Now, if I got any job using reserve function,

$jobB = $pheanstalkB->reserve();

It will give you output as follow, and we can see that beanstalk is not providing tube name from which it fetched this job.

Pheanstalk_Job Object
(
    [_id:Pheanstalk_Job:private] => 2
    [_data:Pheanstalk_Job:private] => Job Data ....
)

As we know that, single worker can watch in N tube(s), so if I want to delay this job and want to put under same tube. How can we find job's tube name?

Thanks...

Was it helpful?

Solution

Beanstalkd doesn't return the tube that the job came from with the job itself, but you can query for it - with the command 'stats-job'.

put 1 0 100 5
hello
INSERTED 10

reserve
RESERVED 10 5
hello

stats-job 10
OK 143
---
id: 10
tube: default
state: reserved
pri: 1
age: 33
delay: 0
ttr: 100
time-left: 82
reserves: 1
timeouts: 0
releases: 0
buries: 0
kicks: 0

I put a simple job in, reserve it (and get the job-ID back: 10), then run 'stats-job', for the id, getting the original tube, and other information.

Pheanstalk has the statsJob function, that you pass in the job (as returned from reserve).

If there was anything else that you can't get about a particular job, you can always put meta-information into the job itself.

OTHER TIPS

Found new way to put job back to same queue with some delay time. We can use direct release function of pheanstalk library. e.g.

    $this->pheanstalk->release($job,$priority,$delay);

This way, we don't need to find job's actual tube and can save concurrency issues, specially in my case.

Thanks for your help !!!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top