Commit 5401e2fe authored by Marc Duez's avatar Marc Duez
Browse files

server: task.py store information about run status and run date

-file views display them
parent a4246548
......@@ -28,7 +28,8 @@ def help():
response.headers['Access-Control-Max-Age'] = 86400
return dict(message=T('help i\'m lost'))
## add a scheduller task to run vidjil on a specific sequence file
def run_request():
import gluon.contrib.simplejson
if request.env.http_origin:
......@@ -43,12 +44,6 @@ def run_request():
error += "id sequence file needed, "
if not "config_id" in request.vars:
error += "id config needed, "
row = db( ( db.data_file.config_id == request.vars["config_id" ] )
& ( db.data_file.sequence_file_id == request.vars["sequence_file_id"] )
).select()
if len(row) > 0 :
error += "run already done, "
row2 = db( ( db.scheduler_task.args == '["'+request.vars["sequence_file_id"]+'", "'+request.vars["config_id"]+'"]' )
& ( db.scheduler_task.status != "FAILED" )
......@@ -61,7 +56,23 @@ def run_request():
error += "run already registered, "
if error == "" :
scheduler.queue_task('run', [request.vars["sequence_file_id"],request.vars["config_id"]]
## create or update data file state
row = db( ( db.data_file.config_id == request.vars["config_id" ] )
& ( db.data_file.sequence_file_id == request.vars["sequence_file_id"] )
).select()
if len(row) > 0 : ## update
data_id = row[0].data_file.id
db.data_file[data_id] = dict(state = 'queued')
else: ## create
data_id = db.data_file.insert(sequence_file_id = request.vars['sequence_file_id'],
config_id = request.vars['config_id'],
status = 'pending'
)
##add task to scheduller
scheduler.queue_task('run', [request.vars["sequence_file_id"],request.vars["config_id"], data_id]
, repeats = 1, timeout = 6000)
res = {"success": "true" , "msg": "request added" }
......
......@@ -124,6 +124,8 @@ db.define_table('config',
db.define_table('data_file',
Field('sequence_file_id', 'reference sequence_file'),
Field('config_id', 'reference config'),
Field('run_date','date'),
Field('status', 'string'),
Field('data_file', 'upload', length=1000000000000))
......
# coding: utf8
def run_vidjil(id_file, id_config):
def run_vidjil(id_file, id_config, id_data):
import time, datetime
from subprocess import Popen, PIPE, STDOUT, os
## les chemins d'acces a vidjil / aux fichiers de sequences
......@@ -30,10 +31,12 @@ def run_vidjil(id_file, id_config):
stream = open(data_filepath, 'rb')
## insertion dans la base de donnée
id = db.data_file.insert(sequence_file_id=id_file,
config_id=id_config,
data_file=stream
)
ts = time.time()
db.data_file[id_data] = dict(status = 'ready',
run_date = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d'),
data_file = stream
)
db.commit()
......
......@@ -37,6 +37,7 @@
<td class="column2"> sampling date </td>
<td> info </td>
<td class="column4"> status </td>
<td class="column2"> vidjil run date </td>
<td class="column5"> </td>
<td class="column5"> </td>
<td class="column5"> </td>
......@@ -62,9 +63,10 @@
<td> {{if row.data_file.id == None :}}
<span class="button" onclick="db.request('default/run_request', { 'sequence_file_id' : '{{=row.sequence_file.id}}' , 'config_id' : {{=config_id}} } )"> run >> </span>
{{else:}}
ready
{{=row.data_file.status}}
{{pass}}
</td>
<td> {{=row.data_file.run_date}} </td>
<td> <a href="{{=URL('download', scheme='http', args=row.sequence_file.data_file)}}" >dl</a> </td>
<td onclick="db.call('file/edit', {'id' :'{{=row.sequence_file.id}}', 'patient_id' :'{{=request.vars['id']}}'} )" > e </td>
<td onclick="db.call('file/confirm', {'id' :'{{=row.sequence_file.id}}', 'patient_id' :'{{=request.vars['id']}}'} )" > X </td>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment