callback on reserve

58 views
Skip to first unread message

Iain C Docherty

unread,
Jun 29, 2016, 2:12:27 PM6/29/16
to beanstalk-talk
I want to communicate to a websocket server (written in Perl) also via a beanstalk queue. However if I use the blocking reserve command then it will not respond to web-socket calls.

I could poll the reserve queue periodically but this is not ideal.

Ideally I would like to implement a callback, but all my searching (both in Google and in this group) brings up nothing.

Any suggestions on how to implement this cleanly?

Kind Regards
Iain

Scott Wiersdorf

unread,
Jun 29, 2016, 3:53:15 PM6/29/16
to beanstalk-talk
I think the only option you have is reserve-with-timeout, but you can set the timeout to be 0s so that it won't block your event loop (I don't know if reserve-with-timeout accepts fractional seconds—try it). You may have to handle the "TIMED_OUT" or "DEADLINE_SOON" responses, so be sure to check for those (depending on what client you're using).

Scott

Nigel Gregoire

unread,
Jun 29, 2016, 8:28:18 PM6/29/16
to beansta...@googlegroups.com
Hello!

I'm not sure what event loop you're using, but you could try
https://metacpan.org/pod/AnyEvent::Beanstalk .

Sample code: http://pastebitch.com/HeQF?perl

That said, we have some event loops at work using reserve-with-timeout
with a timeout of zero, and that's worked fine for us.
> --
> You received this message because you are subscribed to the Google Groups
> "beanstalk-talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to beanstalk-tal...@googlegroups.com.
> To post to this group, send email to beansta...@googlegroups.com.
> Visit this group at https://groups.google.com/group/beanstalk-talk.
> For more options, visit https://groups.google.com/d/optout.



--
Nigel

http://www.forgreatjustice.ca/

Iain C Docherty

unread,
Jun 30, 2016, 12:52:41 AM6/30/16
to beanstalk-talk
Thank you both for those suggestions.

As is often the case, having posted the question, the answer almost immediately is found!

The solution in this case (which I took time to verify) is to use the Perl module AnyEvent::Beanstalk

Kind Regards
Iain
Reply all
Reply to author
Forward
0 new messages