earl / beanstalkc

A simple beanstalkd client library for Python
Apache License 2.0
457 stars 115 forks source link

peek_ready() gets job from 'default' tube even if it's not being watched. #47

Closed ghedsouza closed 10 years ago

ghedsouza commented 10 years ago

If you explicitly watch a single empty tube other than 'default', beanstalkc.Connection.peek_ready() will still return jobs from the 'default' tube.

This is an example, where, starting with a completely empty database, peek_ready() should not return a job, but does anyway:

import beanstalkc

beanstalk = beanstalkc.Connection(
    host='127.0.0.1',
    port=11301,
    )

assert beanstalk.using() == 'default'
beanstalk.put('test_job_default')

beanstalk.watch('xxx')
beanstalk.ignore('default')
assert beanstalk.watching() == ['xxx']

job = beanstalk.peek_ready()             # Should not get a job here:
assert job.body == 'test_job_default'

Versions: beanstalkd = 1.9 beanstalkc = 0.4.0

ghedsouza commented 10 years ago

If you call beanstalk.use('xxx') before peek_ready(), then it returns None, as expected.

earl commented 10 years ago

peek_buried, peek_delayed, and peek_ready operate on the currently _use_d tube. Quoting the official protocol documentation:

"The peek commands let the client inspect a job in the system. There are four variations. All but the first operate only on the currently used tube."

This is a gotcha that deserves a mention in our own tutorial documentation as well. There's already an issue tracking that documentation update: #19.