Last active
August 15, 2017 23:40
-
-
Save ktilcu/d4f07cc7b4744db7b4f2 to your computer and use it in GitHub Desktop.
kyle-Snippet: Kick buried beanstalk jobs and catalog them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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