cleaned up
This commit is contained in:
@@ -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(
|
||||
{
|
||||
|
||||
@@ -14,9 +14,7 @@ from django.views.generic.base import TemplateView
|
||||
from django.db.models import Q
|
||||
from django import template
|
||||
from django.db import IntegrityError, transaction
|
||||
#from django.contrib.sessions.backends.db import SessionStore
|
||||
from importlib import import_module
|
||||
from django.contrib.sessions.models import Session
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.http import (
|
||||
HttpResponse, HttpResponseRedirect,
|
||||
@@ -143,10 +141,6 @@ from rq import Queue,cancel_job
|
||||
|
||||
from django.core.cache import cache
|
||||
|
||||
# Redis related
|
||||
session_engine = import_module(settings.SESSION_ENGINE)
|
||||
|
||||
|
||||
def getvalue(data):
|
||||
perc = 0
|
||||
total = 1
|
||||
@@ -178,7 +172,7 @@ class SessionTaskListener(threading.Thread):
|
||||
data = json.loads(item['data'])
|
||||
total,done,id,session_key = getvalue(data)
|
||||
perc = 100.*done/total
|
||||
cache.set(id,perc)
|
||||
cache.set(id,perc,3600)
|
||||
|
||||
except TypeError:
|
||||
pass
|
||||
@@ -245,7 +239,7 @@ def remove_asynctask(request,id):
|
||||
newtasks = []
|
||||
for task in oldtasks:
|
||||
if id not in task[0]:
|
||||
newtasks += [(task[0],task[1],task[2])]
|
||||
newtasks += [(task[0],task[1])]
|
||||
|
||||
request.session['async_tasks'] = newtasks
|
||||
|
||||
@@ -340,9 +334,9 @@ def test_job_view(request,aantal=100):
|
||||
|
||||
|
||||
try:
|
||||
request.session['async_tasks'] += [(job.id,'long_test_task',0)]
|
||||
request.session['async_tasks'] += [(job.id,'long_test_task')]
|
||||
except KeyError:
|
||||
request.session['async_tasks'] = [(job.id,'long_test_task',0)]
|
||||
request.session['async_tasks'] = [(job.id,'long_test_task')]
|
||||
|
||||
url = reverse(session_jobs_status)
|
||||
|
||||
@@ -394,7 +388,7 @@ def get_stored_tasks_status(request):
|
||||
taskids = []
|
||||
|
||||
taskstatus = []
|
||||
for id,func_name,session_progress in taskids:
|
||||
for id,func_name in taskids:
|
||||
progress = 0
|
||||
cached_progress = cache.get(id)
|
||||
finished = get_job_status(id)['finished']
|
||||
@@ -404,7 +398,7 @@ def get_stored_tasks_status(request):
|
||||
elif cached_progress>0:
|
||||
progress = cached_progress
|
||||
else:
|
||||
progress = session_progress
|
||||
progress = 0
|
||||
|
||||
this_task_status = {
|
||||
'id':id,
|
||||
@@ -3345,9 +3339,9 @@ def otwrankings_view(request,theuser=0,
|
||||
)
|
||||
request.session['job_id'] = job.id
|
||||
try:
|
||||
request.session['async_tasks'] += [(job.id,'updatecpwater',0)]
|
||||
request.session['async_tasks'] += [(job.id,'updatecpwater')]
|
||||
except KeyError:
|
||||
request.session['async_tasks'] = [(job.id,'updatecpwater',0)]
|
||||
request.session['async_tasks'] = [(job.id,'updatecpwater')]
|
||||
messages.info(request,'New calculation queued. Refresh page or resubmit the date form to get the result')
|
||||
|
||||
powerdf = pd.DataFrame({
|
||||
@@ -3602,9 +3596,9 @@ def oterankings_view(request,theuser=0,
|
||||
)
|
||||
request.session['job_id'] = job.id
|
||||
try:
|
||||
request.session['async_tasks'] += [(job.id,'updatecp',0)]
|
||||
request.session['async_tasks'] += [(job.id,'updatecp')]
|
||||
except KeyError:
|
||||
request.session['async_tasks'] = [(job.id,'updatecp',0)]
|
||||
request.session['async_tasks'] = [(job.id,'updatecp')]
|
||||
messages.info(request,'New calculation queued.')
|
||||
|
||||
powerdf = pd.DataFrame({
|
||||
@@ -5736,9 +5730,9 @@ def workout_otwsetpower_view(request,id=0,message="",successmessage=""):
|
||||
ratio=r.cpratio)
|
||||
|
||||
try:
|
||||
request.session['async_tasks'] += [(job.id,'otwsetpower',0)]
|
||||
request.session['async_tasks'] += [(job.id,'otwsetpower')]
|
||||
except KeyError:
|
||||
request.session['async_tasks'] = [(job.id,'otwsetpower',0)]
|
||||
request.session['async_tasks'] = [(job.id,'otwsetpower')]
|
||||
|
||||
successmessage = 'Your calculations have been submitted. You will receive an email when they are done. You can check the status of your calculations <a href="/rowers/jobs-status/">here</a>'
|
||||
messages.info(request,successmessage)
|
||||
@@ -7514,9 +7508,9 @@ def workout_add_chart_view(request,id,plotnr=1):
|
||||
imagename=imagename
|
||||
)
|
||||
try:
|
||||
request.session['async_tasks'] += [(jobid,'make_plot',0)]
|
||||
request.session['async_tasks'] += [(jobid,'make_plot')]
|
||||
except KeyError:
|
||||
request.session['async_tasks'] = [(jobid,'make_plot',0)]
|
||||
request.session['async_tasks'] = [(jobid,'make_plot')]
|
||||
|
||||
try:
|
||||
url = request.session['referer']
|
||||
|
||||
Reference in New Issue
Block a user