Private
Public Access
1
0

cleaned up

This commit is contained in:
Sander Roosendaal
2017-11-01 17:34:46 +01:00
parent ac5500a1d8
commit 1847ab37e3
2 changed files with 15 additions and 52 deletions

View File

@@ -29,41 +29,11 @@ def getvalue(data):
return total,done,id,session_key
class Listener(threading.Thread):
def __init__(self, r, channels):
threading.Thread.__init__(self)
self.redis = r
self.pubsub = self.redis.pubsub()
self.pubsub.subscribe(channels)
def work(self, item):
try:
data = json.loads(item['data'])
total,done,id,session_key = getvalue(data)
perc = 100.*done/total
print perc, '%'
print session_key, id
except TypeError:
print "invalid data"
def run(self):
for item in self.pubsub.listen():
if item['data'] == "KILL":
self.pubsub.unsubscribe()
print self, "unsubscribed and finished"
break
else:
self.work(item)
def longtask(aantal,jobid=None,debug=False,
session_key=None):
counter = 0
# if jobid:
# if debug:
# job = celery_result.AsyncResult(jobid)
# else:
# job = Job.fetch(jobid,connection=redis_connection)
channel = 'tasks'
for i in range(aantal):
@@ -73,7 +43,6 @@ def longtask(aantal,jobid=None,debug=False,
counter = 0
if debug:
progress = 100.*i/aantal
print progress
if jobid != None:
redis_connection.publish(channel,json.dumps(
{