redis monitor for CP update jobs
Stores job id in a cookie. Upon reload, checks if job is still busy. If busy, no new jobs are started. Some messaging for users to give them information about the job status.
This commit is contained in:
@@ -131,6 +131,16 @@ queue = django_rq.get_queue('default')
|
||||
queuelow = django_rq.get_queue('low')
|
||||
queuehigh = django_rq.get_queue('low')
|
||||
|
||||
from redis import StrictRedis
|
||||
from rq.exceptions import NoSuchJobError
|
||||
from rq.registry import StartedJobRegistry
|
||||
from rq import Queue
|
||||
|
||||
redis_connection = StrictRedis()
|
||||
rq_registry = StartedJobRegistry(queue.name,connection=redis_connection)
|
||||
|
||||
from rq.job import Job
|
||||
|
||||
from rest_framework_swagger.views import get_swagger_view
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
from rest_framework.parsers import JSONParser
|
||||
@@ -155,10 +165,30 @@ from scipy.interpolate import griddata
|
||||
USER_LANGUAGE = 'en-US'
|
||||
|
||||
from interactiveplots import *
|
||||
from rowers.celery import result as celery_result
|
||||
|
||||
# Define the API documentation
|
||||
schema_view = get_swagger_view(title='Rowsandall API')
|
||||
|
||||
def get_job_result(jobid):
|
||||
if settings.DEBUG:
|
||||
result = celery_result.AsyncResult(jobid).result
|
||||
else:
|
||||
running_job_ids = rq_registry.get_job_ids()
|
||||
if len(running_job_ids) and jobid in running_job_ids:
|
||||
# job is running
|
||||
return None
|
||||
else:
|
||||
# job is ready
|
||||
try:
|
||||
job = Job.fetch(jobid,connection=redis_connection)
|
||||
result = job.result
|
||||
except NoSuchJobError:
|
||||
return None
|
||||
|
||||
return result
|
||||
|
||||
|
||||
# Test if row data include candidates
|
||||
def rowhascoordinates(row):
|
||||
# create interactive plot
|
||||
@@ -3076,6 +3106,32 @@ def otwrankings_view(request,theuser=0,
|
||||
|
||||
|
||||
delta,cpvalue,avgpower = dataprep.fetchcp(r,theworkouts)
|
||||
|
||||
runningjob = 0
|
||||
|
||||
try:
|
||||
jobid = request.session['job_id']
|
||||
if jobid:
|
||||
result = get_job_result(jobid)
|
||||
if result:
|
||||
messages.info(request,'Your calculation is ready')
|
||||
runningjob = 1
|
||||
request.session['job_id'] = 0
|
||||
else:
|
||||
runningjob = 1
|
||||
messages.info(request,'Your job is still running')
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
||||
if not runningjob:
|
||||
job = dataprep.runcpupdate(
|
||||
r,type='water',
|
||||
startdate=startdate,
|
||||
enddate=enddate
|
||||
)
|
||||
request.session['job_id'] = job.id
|
||||
messages.info(request,'New calculation queued. Refresh page or resubmit the date form to get the result')
|
||||
|
||||
powerdf = pd.DataFrame({
|
||||
'Delta':delta,
|
||||
@@ -3181,6 +3237,7 @@ def otwrankings_view(request,theuser=0,
|
||||
'startdate':startdate,
|
||||
'enddate':enddate,
|
||||
'teams':get_my_teams(request.user),
|
||||
'workouttype':'water',
|
||||
})
|
||||
# Show ranking distances including predicted paces
|
||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
||||
@@ -3298,7 +3355,33 @@ def oterankings_view(request,theuser=0,
|
||||
delta,cpvalue,avgpower = dataprep.fetchcp(
|
||||
r,theworkouts,table='cpergdata'
|
||||
)
|
||||
|
||||
runningjob = 0
|
||||
|
||||
try:
|
||||
jobid = request.session['job_id']
|
||||
if jobid:
|
||||
result = get_job_result(jobid)
|
||||
if result:
|
||||
messages.info(request,'Your calculation is ready')
|
||||
runningjob = 1
|
||||
request.session['job_id'] = 0
|
||||
else:
|
||||
runningjob = 1
|
||||
messages.info(request,'Your job is still running')
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
||||
if not runningjob:
|
||||
job = dataprep.runcpupdate(
|
||||
r,type='rower',
|
||||
startdate=startdate,
|
||||
enddate=enddate
|
||||
)
|
||||
request.session['job_id'] = job.id
|
||||
messages.info(request,'New calculation queued. Refresh page or resubmit the date form to get the result')
|
||||
|
||||
powerdf = pd.DataFrame({
|
||||
'Delta':delta,
|
||||
'CP':cpvalue,
|
||||
@@ -3320,11 +3403,11 @@ def oterankings_view(request,theuser=0,
|
||||
div = res[1]
|
||||
p1 = res[2]
|
||||
ratio = res[3]
|
||||
r.p0 = p1[0]
|
||||
r.p1 = p1[1]
|
||||
r.p2 = p1[2]
|
||||
r.p3 = p1[3]
|
||||
r.cpratio = ratio
|
||||
r.ep0 = p1[0]
|
||||
r.ep1 = p1[1]
|
||||
r.ep2 = p1[2]
|
||||
r.ep3 = p1[3]
|
||||
r.ecpratio = ratio
|
||||
r.save()
|
||||
paulslope = 1
|
||||
paulintercept = 1
|
||||
@@ -3403,6 +3486,7 @@ def oterankings_view(request,theuser=0,
|
||||
'startdate':startdate,
|
||||
'enddate':enddate,
|
||||
'teams':get_my_teams(request.user),
|
||||
'workouttype':'rower',
|
||||
})
|
||||
|
||||
# Reload the workout and calculate the summary from the stroke data (lapIDx)
|
||||
@@ -5427,7 +5511,7 @@ def workout_otwsetpower_view(request,id=0,message="",successmessage=""):
|
||||
ratio=r.cpratio)
|
||||
else:
|
||||
res = queuelow.enqueue(handle_otwsetpower,f1,boattype,
|
||||
weightvalue,
|
||||
weightvalue,
|
||||
first_name,last_name,emailaddress,id,
|
||||
ps=[r.p0,r.p1,r.p2,r.p3],
|
||||
ratio=r.cpratio)
|
||||
|
||||
Reference in New Issue
Block a user