Skip to content

Commit

Permalink
Touch support.
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin committed Nov 20, 2008
1 parent 300ef52 commit f572345
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions beanstalk/job.py
Expand Up @@ -113,6 +113,17 @@ def Finish(self):
else:
return True

@honorimmutable
def Touch(self):
try:
self.conn.touch(self.id)
except errors.NotFound:
return False
except:
raise
else:
return True

@honorimmutable
def Bury(self, newpri = 0):
if newpri:
Expand Down
13 changes: 13 additions & 0 deletions beanstalk/protohandler.py
Expand Up @@ -306,6 +306,19 @@ def process_kick(bound=10):
"""
return 'kick %s\r\n' % (bound,)

@interaction(ok='TOUCHED')
def process_touch(jid):
"""
touch
send:
touch <job>
return:
TOUCHED
NOT_FOUND
"""
return 'touch %s\r\n' % (jid,)

@interaction(ok='OK', ok_args=['bytes'], has_data=True, parse=yaml.load)
def process_stats():
"""
Expand Down
1 change: 1 addition & 0 deletions examples/simple_clients.py
Expand Up @@ -20,6 +20,7 @@ def consumer_main(connection):
while True:
j = connection.reserve()
print 'got job! job is: %s' % j.data
j.Touch()
j.Finish()

def main():
Expand Down
1 change: 1 addition & 0 deletions examples/twisted_consumer.py
Expand Up @@ -11,6 +11,7 @@

def executor(bs, jobdata):
print "Running job %s" % `jobdata`
bs.touch(jobdata['jid'])
bs.delete(jobdata['jid'])

def error_handler(e):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_Proto.py
Expand Up @@ -37,6 +37,13 @@
('DELETED\r\n',{'state':'ok'})
]
],
[
('process_touch', (185,)),
'touch 185\r\n',
[
('TOUCHED\r\n',{'state':'ok'})
]
],
[
('process_release', (33,22,17)),
'release 33 22 17\r\n',
Expand Down

0 comments on commit f572345

Please sign in to comment.