Private
Public Access
1
0

task progress monitoring celery works on client

This commit is contained in:
Sander Roosendaal
2017-11-01 00:16:05 +01:00
parent 5525dad1f6
commit fb85e5f53b
4 changed files with 100 additions and 8 deletions

View File

@@ -99,7 +99,7 @@ from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,
from rowers.tasks import (
handle_sendemail_unrecognized,handle_sendemailnewcomment,
handle_sendemailnewresponse, handle_updatedps,
handle_updatecp
handle_updatecp,long_test_task
)
from scipy.signal import savgol_filter
@@ -138,6 +138,12 @@ from rq import Queue,cancel_job
queuefailed = Queue("failed",connection=Redis())
redis_connection = StrictRedis()
r = Redis()
from .longtask import Listener
client = Listener(r,['tasks'])
client.start()
rq_registry = StartedJobRegistry(queue.name,connection=redis_connection)
rq_registryhigh = StartedJobRegistry(queuehigh.name,connection=redis_connection)
rq_registrylow = StartedJobRegistry(queuelow.name,connection=redis_connection)
@@ -188,7 +194,7 @@ def remove_asynctask(request,id):
request.session['async_tasks'] = newtasks
def get_job_result(jobid):
if settings.EBUG:
if settings.DEBUG:
result = celery_result.AsyncResult(jobid).result
else:
running_job_ids = rq_registry.get_job_ids()
@@ -210,12 +216,16 @@ verbose_job_status = {
'updatecpwater': 'Critical Power Calculation for OTW Workouts',
'otwsetpower': 'Rowing Physics OTW Power Calculation',
'make_plot': 'Create static chart',
'long_test_task': 'Long Test Task',
}
def get_job_status(jobid):
if settings.DEBUG:
job = celery_result.AsyncResult(jobid)
jobresult = job.result
channel = 'task:<'+job.id+'>:progress'
channel = 'noot'
if 'fail' in job.status.lower():
jobresult = '0'
summary = {
@@ -264,7 +274,20 @@ def kill_async_job(request,id='aap'):
url = reverse(session_jobs_status)
return HttpResponseRedirect(url)
@login_required()
def test_job_view(request,aantal=100):
job = myqueue(queuehigh,long_test_task,int(aantal))
try:
request.session['async_tasks'] += [(job.id,'long_test_task')]
except KeyError:
request.session['async_tasks'] = [(job.id,'long_test_task')]
url = reverse(session_jobs_status)
return HttpResponseRedirect(url)
def get_all_queued_jobs(userid=0):
r = StrictRedis()
@@ -6528,7 +6551,6 @@ def workout_flexchart3_view(request,*args,**kwargs):
if request.user == row.user.user:
mayedit=1
workouttype = 'ote'
if row.workouttype in ('water','coastal'):
workouttype = 'otw'
@@ -6578,8 +6600,9 @@ def workout_flexchart3_view(request,*args,**kwargs):
else:
yparam2 = 'hr'
if favoritenr>=0 and r.showfavoritechartnotes:
favoritechartnotes = favorites[favoritenr].notes
if not request.user.is_anonymous():
if favoritenr>=0 and r.showfavoritechartnotes:
favoritechartnotes = favorites[favoritenr].notes
else:
favoritechartnotes = ''
favoritenr = 0