Skip to content

Commit

Permalink
Fixed some little bugs i found, cleanup some code, move examples.py t…
Browse files Browse the repository at this point in the history
…o the examples directory and other sensical stuff
  • Loading branch information
sophacles committed May 6, 2008
1 parent fce36a1 commit 14e8e49
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
13 changes: 6 additions & 7 deletions beanstalk/job.py
@@ -1,14 +1,14 @@
from functools import wraps
import yaml
from errors import FailureError, JobError
import errors

DEFAULT_CONN = None

def honorimmutable(func):
@wraps(func)
def deco(*args, **kw):
if args[0]._imutable:
raise JobError("Cannot do that to a job you don't own")
if args[0].imutable:
raise errors.JobError("Cannot do that to a job you don't own")
return func(*args, **kw)
return deco

Expand Down Expand Up @@ -49,13 +49,12 @@ def __init__(self, conn = None, jid=0, pri=0, data='', state = 'ok',**kw):
else:
self.data = ''

self._imutable = bool(kw.get('imutable'), False)
self.imutable = bool(kw.get('imutable', False))
self._from_queue = bool(kw.get('from_queue', False))
self.tube = kw.get('tube', 'default')

def __del__(self):
self.Delete()
super(Job, self).__del__()
self.Finish()

def __str__(self):
return self._serialize()
Expand All @@ -73,7 +72,7 @@ def Queue(self):
if self._from_queue:
self.Delay(self.delay)
return
oldtube = self.conn.current_tube
oldtube = self.conn.tube
if oldtube != self.tube:
self.conn.use(self.tube)
self.conn.put(self._serialize(), self.priority, self.delay)
Expand Down
4 changes: 2 additions & 2 deletions beanstalk/serverconn.py
Expand Up @@ -58,8 +58,8 @@ def _get_response(self, handler):
res = handler(recv)
if res: break

if self.job and 'jid' in job:
res = self.job(res)
if self.job and 'jid' in res:
res = self.job(conn=self,**res)
return res


Expand Down
8 changes: 4 additions & 4 deletions examples/example.py → examples/simple_clients.py
Expand Up @@ -4,24 +4,24 @@
import select

# pybeanstalk imports
import serverconn
import job
from beanstalk import serverconn
from beanstalk import job

def producer_main(connection):
i = 0
while True:
data = 'This is data to be consumed (%s)!' % (i,)
print data
data = job.Job(data=data, conn=connection)
data.put()
data.Queue()
time.sleep(1)
i += 1;

def consumer_main(connection):
while True:
j = connection.reserve()
print 'got job! job is: %s' % j.data
j.delete()
j.Finish()

def main():
try:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -13,7 +13,7 @@
'''

setup(name='pybeanstalk',
version='0.10.0',
version='0.11.1',
description='A python client library for beanstalkd.',
long_description = description_long,
author='Erich Heine',
Expand Down

0 comments on commit 14e8e49

Please sign in to comment.