alternative approach
This commit is contained in:
@@ -10,6 +10,8 @@ redis_connection = StrictRedis()
|
||||
|
||||
import redis
|
||||
import threading
|
||||
import requests
|
||||
from django.conf import settings
|
||||
|
||||
def getvalue(data):
|
||||
perc = 0
|
||||
@@ -55,4 +57,23 @@ def longtask(aantal,jobid=None,debug=False,
|
||||
|
||||
|
||||
|
||||
return 1
|
||||
|
||||
def longtask2(aantal,jobid=None,debug=False):
|
||||
counter = 0
|
||||
|
||||
channel = 'tasks'
|
||||
for i in range(aantal):
|
||||
time.sleep(1)
|
||||
counter += 1
|
||||
if counter > 10:
|
||||
counter = 0
|
||||
if debug:
|
||||
progress = int(100.*i/aantal)
|
||||
if jobid != None:
|
||||
url = settings.SITE_URL+"/rowers/record-progress/"
|
||||
url += str(progress)+"/"+jobid
|
||||
s = requests.get(url)
|
||||
|
||||
|
||||
return 1
|
||||
|
||||
@@ -52,6 +52,12 @@ def long_test_task(self,aantal,debug=False,job=None,session_key=None):
|
||||
return longtask.longtask(aantal,jobid=job.id,debug=debug,
|
||||
session_key=session_key)
|
||||
|
||||
@app.task(bind=True)
|
||||
def long_test_task2(self,aantal,debug=False,job=None):
|
||||
job = self.request
|
||||
|
||||
return longtask.longtask2(aantal,jobid=job.id,debug=debug)
|
||||
|
||||
# create workout
|
||||
@app.task
|
||||
def handle_new_workout_from_file(r, f2,
|
||||
|
||||
@@ -142,6 +142,8 @@ urlpatterns = [
|
||||
url(r'^jobs-status/$',views.session_jobs_status),
|
||||
url(r'^job-kill/(?P<id>.*)$',views.kill_async_job),
|
||||
url(r'^test-job/(?P<aantal>\d+)$',views.test_job_view),
|
||||
url(r'^test-job2/(?P<aantal>\d+)$',views.test_job_view2),
|
||||
url(r'^record-progress/(?P<value>\d+)/(?P<id>.*)$',views.post_progress),
|
||||
url(r'^list-graphs/$',views.graphs_view),
|
||||
url(r'^(?P<theuser>\d+)/ote-bests/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.rankings_view),
|
||||
url(r'^(?P<theuser>\d+)/ote-bests/(?P<deltadays>\d+)$',views.rankings_view),
|
||||
|
||||
@@ -100,7 +100,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,long_test_task
|
||||
handle_updatecp,long_test_task,long_test_task2
|
||||
)
|
||||
|
||||
from scipy.signal import savgol_filter
|
||||
@@ -269,6 +269,7 @@ verbose_job_status = {
|
||||
'otwsetpower': 'Rowing Physics OTW Power Calculation',
|
||||
'make_plot': 'Create static chart',
|
||||
'long_test_task': 'Long Test Task',
|
||||
'long_test_task2': 'Long Test Task 2',
|
||||
}
|
||||
|
||||
def get_job_status(jobid):
|
||||
@@ -344,7 +345,31 @@ def test_job_view(request,aantal=100):
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
@login_required()
|
||||
def test_job_view2(request,aantal=100):
|
||||
|
||||
|
||||
job = myqueue(queuehigh,long_test_task2,int(aantal))
|
||||
|
||||
|
||||
try:
|
||||
request.session['async_tasks'] += [(job.id,'long_test_task2')]
|
||||
except KeyError:
|
||||
request.session['async_tasks'] = [(job.id,'long_test_task2')]
|
||||
|
||||
url = reverse(session_jobs_status)
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
def post_progress(request,id=None,value=0):
|
||||
if id:
|
||||
cache.set(id,value,3600)
|
||||
|
||||
# test
|
||||
result = cache.get(id)
|
||||
|
||||
return HttpResponse('progress cached '+str(result),status=200)
|
||||
|
||||
def get_all_queued_jobs(userid=0):
|
||||
r = StrictRedis()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user