On Sun, Jan 11, 2009 at 10:45 AM, Linan Wang <[email protected]> wrote:
> I'd a like to request a feature in the next version, which is a special kind
> of messages/tasks that are guaranteed to be received once by every worker.
> This feature is very useful to control worker's behavior. e.g. upgrading
> worker to newer version, direct workers to ignore some task. If workers are
> programed in scripting languages like python or ruby, the feature can be
> used to update small chunk of codes.
You can already do this without help from the server (modulo the
general limits on beanstalk's guarantees).
Here's a recipe:
For now I'll refer to these special exactly-once-for-each-worker jobs
simply as "messages".
Have each client listen on an extra tube, "messages-0", in addition to
its usual tubes.
When you want to send a message, put it in this tube.
When a worker receives a message, it should:
1. Watch messages-1
2. Ignore messages-0
3. If there are no watchers on messages-0,
delete the message
else, release the message
4. Act on the message (e.g. run the job as usual)
Perhaps the order of these actions should be different for best reliability.
The name of the message tube doesn't need to contain a simple sequence
number, but it should somehow change every time in a predictable way.
There are still some race conditions, but I think those can be avoided
if you are careful to send only one message at a time. That is, you'd
have to wait for all workers to process each message before sending
the next one. I believe this limitation is fixable.
Also, it's probably best to encode the entire worker procedure as the
payload of a normal job, that way workers don't need any
special-purpose code built in.
As a bonus, when erlang-style mailboxes are implemented, step 3 can
become simply "release the message".
kr
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"beanstalk-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/beanstalk-talk?hl=en
-~----------~----~----~----~------~----~------~--~---