status progress bar works on develop
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
import numpy as np
|
||||
import time
|
||||
|
||||
@@ -10,6 +11,24 @@ redis_connection = StrictRedis()
|
||||
import redis
|
||||
import threading
|
||||
|
||||
def getvalue(data):
|
||||
perc = 0
|
||||
total = 1
|
||||
done = 0
|
||||
id = 0
|
||||
session_key = 'noot'
|
||||
for i in data.iteritems():
|
||||
if i[0] == 'total':
|
||||
total = float(i[1])
|
||||
if i[0] == 'done':
|
||||
done = float(i[1])
|
||||
if i[0] == 'id':
|
||||
id = i[1]
|
||||
if i[0] == 'session_key':
|
||||
session_key = i[1]
|
||||
|
||||
return total,done,id,session_key
|
||||
|
||||
class Listener(threading.Thread):
|
||||
def __init__(self, r, channels):
|
||||
threading.Thread.__init__(self)
|
||||
@@ -18,8 +37,15 @@ class Listener(threading.Thread):
|
||||
self.pubsub.subscribe(channels)
|
||||
|
||||
def work(self, item):
|
||||
print item['channel'], ":", item['data']
|
||||
|
||||
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":
|
||||
@@ -30,13 +56,15 @@ class Listener(threading.Thread):
|
||||
self.work(item)
|
||||
|
||||
|
||||
def longtask(aantal,jobid=None,debug=False):
|
||||
if jobid:
|
||||
if debug:
|
||||
job = celery_result.AsyncResult(jobid)
|
||||
else:
|
||||
job = Job.fetch(jobid,connection=redis_connection)
|
||||
counter = 0
|
||||
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):
|
||||
time.sleep(1)
|
||||
@@ -51,11 +79,11 @@ def longtask(aantal,jobid=None,debug=False):
|
||||
{
|
||||
'done':i,
|
||||
'total':aantal,
|
||||
'id':jobid,
|
||||
'id':jobid,
|
||||
'session_key':session_key,
|
||||
}
|
||||
))
|
||||
|
||||
|
||||
redis_connection.publish(channel,'KILL')
|
||||
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user