Skip to content

Instantly share code, notes, and snippets.

@ktilcu
Last active August 15, 2017 23:40
Show Gist options
  • Save ktilcu/d4f07cc7b4744db7b4f2 to your computer and use it in GitHub Desktop.
Save ktilcu/d4f07cc7b4744db7b4f2 to your computer and use it in GitHub Desktop.
kyle-Snippet: Kick buried beanstalk jobs and catalog them
import beanstalkc
f = open('myfile.json','w')
y = []
def process_buried_jobs(tube, buried):
beanstalk.use(tube)
x = 0
while x < buried:
job = beanstalk.peek_buried()
y.append(job.body)
stats = job.stats()
if stats['buries'] > 20:
job.delete()
try:
job.kick()
except:
pass
x += 1
beanstalk = beanstalkc.Connection(host='localhost', port=11300)
for tube in beanstalk.tubes():
buried = beanstalk.stats_tube(tube)['current-jobs-buried']
if buried > 0:
process_buried_jobs(tube, buried)
beanstalk.close()
f.write("%s" % y)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment