earl / beanstalkc

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

CommandFailed: ('delete', 'NOT_FOUND', []) #66

Closed edwardmp closed 7 years ago

edwardmp commented 8 years ago

Hi,

I'm getting the following stacktrace after I call the delete method on a job:

Traceback (most recent call last):
  File "/var/lib/plateprocessor/processor.py", line 57, in main
    process_beanstalk_messages()
  File "/var/lib/plateprocessor/processor.py", line 30, in process_beanstalk_messages
    job.delete()
  File "/usr/local/lib/python2.7/site-packages/beanstalkc.py", line 272, in delete
    self.conn.delete(self.jid)
  File "/usr/local/lib/python2.7/site-packages/beanstalkc.py", line 229, in delete
    self._interact('delete %d\r\n' % jid, ['DELETED'], ['NOT_FOUND'])
  File "/usr/local/lib/python2.7/site-packages/beanstalkc.py", line 91, in _interact
    raise CommandFailed(command.split()[0], status, results)
CommandFailed: ('delete', 'NOT_FOUND', [])

My code (simplified):

def process_beanstalk_messages():
    beanstalk = beanstalkc.Connection(host=BEANSTALK_HOST, port=BEANSTALK_PORT)
    beanstalk.use(BEANSTALK_ALPRD_QUEUE_NAME)
    beanstalk.watch(BEANSTALK_ALPRD_QUEUE_NAME)

    print("Listening for beanstalk messages..")
    while True:
        job = beanstalk.peek_ready()
        if job is not None:
            logging.info("Received message from beanstalk queue")
            try:
                something()
            except Exception as exception:
                logging.error("Exception ocurred: %s" % exception)
            job.delete()
svisser commented 7 years ago

@edwardmp you need to use beanstalk.reserve() to receive the job from beanstalk.

peek_ready() allows you to peek at a job but it doesn't reserve it. It's then possible that another process picks it up, handles it and deletes it before this code does.

edwardmp commented 7 years ago

@svisser Thanks, I see I already changed my code in the meantime to accomodate for that. Closing this issue.

SumedhaJagtap commented 6 years ago

@edwardmp How did you solve this issue?

edwardmp commented 6 years ago

@SumedhaJagtap I did exactly what @svisser said above ;)