Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Add Command: "wait <id>" that responds when a job is deleted #203

Open
wants to merge 7 commits into
from

Conversation

Projects
None yet
1 participant
Contributor

danielbeardsley commented Aug 28, 2013

Add a command: wait <id>\r\n that responds with DELETED <id>\r\n or BURIED <id>\r\n only once a job has been deleted or buried.

This allows a client to be notified about the status of a job without polling.

From the docs

The wait command waits until a particular job is out of the system before responding. It can be used to block a client until a job is completed. It looks like this:

wait <id>\r\n
wait options
  • <id> is the job id to wait for.
wait responses

The client expects one line of response once the state of the job has changed, which may be:

  • DELETED <id>\r\n to indicate the job was deleted via the delete command (normal success).
  • BURIED <id>\r\n to indicate the job was buried via the bury command.
  • NOT_FOUND\r\n if the job id does not exist.

A response won't be sent by the server until the specified job is deleted or buried. The wait command can be issued multiple times before a response is received in order to wait on a collection of jobs.

danielbeardsley added some commits Aug 27, 2013

@danielbeardsley danielbeardsley add command: 'wait jobid' to block on deletion
First working version
8dd0b0d
@danielbeardsley danielbeardsley CMD_WAITJOB: reply with appropriate message
When a job is deleted reply with 'DELETED'.
When a job is buried reply with 'BURIED'.
f62fda6
@danielbeardsley danielbeardsley CMD_WAITJOB: respond immediately if already buried
Also, respond with job id so jobs can be waited on in parallel.

Add more tests!
2bbc48f
@danielbeardsley danielbeardsley Docs: add info about WAIT command 80652b8
Contributor

danielbeardsley commented Aug 28, 2013

I will gladly squash this into one commit with a longer commit message if you'd like.

@danielbeardsley danielbeardsley added a commit to iFixit/php-beanstalk that referenced this pull request Sep 2, 2013

@danielbeardsley danielbeardsley Add wait() command to block on job completion
See kr/beanstalkd#203 for explanation
cbdec77

@danielbeardsley danielbeardsley added a commit to iFixit/php-beanstalk that referenced this pull request Sep 2, 2013

@danielbeardsley danielbeardsley Add wait() command to block on job completion
See kr/beanstalkd#203 for explanation
689e0fe

danielbeardsley added some commits Oct 2, 2013

@danielbeardsley danielbeardsley Tests for 'wait' command: Improve reliability
I was seeing intermittent failures on CentOS5 until I made these
changes.

The usleep() calls should go between receiving a job and deleting it.
Improve the assertion error messages
28e629c
@danielbeardsley danielbeardsley CMD_WAITJOB: print 64bit ints correctly
Using the Macros from inttypes.h for printf. This is done for platform and
architecture compatability.
1c3b042
@danielbeardsley danielbeardsley Tests: increase some delays slightly
I was getting rare errors where the time diff was close to 100ms,
but just under (99ms) adn thus failing the test. The point of these
tests is to ensure that the wait causes the blocking. Adding a few ms
time buffer in there made the tests more reliable.
fe9066b
Contributor

danielbeardsley commented Mar 4, 2014

At www.iFixit.com We've been using this feature in production for several months and it's been working great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment