Commit a533c32c authored by Marc Duez's avatar Marc Duez
Browse files

server : task security never schedule a run twice

parent 75e96632
......@@ -52,16 +52,6 @@ def run_request():
if not auth.has_permission('admin', 'patient', id_patient) :
error += "you don't have permission to run request for this patient ("+str(id_patient)+"), "
row2 = db( ( db.scheduler_task.args == '["'+request.vars["sequence_file_id"]+'", "'+request.vars["config_id"]+'"]' )
& ( db.scheduler_task.status != "FAILED" )
& ( db.scheduler_task.status != "EXPIRED" )
& ( db.scheduler_task.status != "TIMEOUT" )
& ( db.scheduler_task.status != "COMPLETED" )
).select()
if len(row2) > 0 :
error += "run already registered, "
if error == "" :
res = schedule_run(request.vars["sequence_file_id"], request.vars["config_id"])
......
# coding: utf8
def schedule_run(id_sequence, id_config):
import time, datetime, sys, os.path
from subprocess import Popen, PIPE, STDOUT, os
id_patient = db.sequence_file[id_sequence].patient_id
row = db( ( db.data_file.config_id == id_config )
& ( db.data_file.sequence_file_id == id_sequence )
).select()
#check data_file
row = db( ( db.data_file.config_id == id_config ) &
( db.data_file.sequence_file_id == id_sequence )
).select()
if len(row) > 0 : ## update
data_id = row[0].id
else: ## create
data_id = db.data_file.insert(sequence_file_id = id_sequence,
config_id = id_config,
)
## create or update fuse file state
row = db( ( db.fused_file.config_id == id_config ) &
config_id = id_config )
## check fused_file
row2 = db( ( db.fused_file.config_id == id_config ) &
( db.fused_file.patient_id == id_patient )
).select()
if len(row) > 0 : ## update
fuse_id = row[0].id
if len(row2) > 0 : ## update
fuse_id = row2[0].id
else: ## create
fuse_id = db.fused_file.insert(patient_id = id_patient,
config_id = id_config)
##check scheduled run
row3 = db( ( db.scheduler_task.args == '["' + id_sequence + '", "' + id_config + '", ' + str(data_id) + ', ' + str(fuse_id) + ']' )
& ( db.scheduler_task.status != "FAILED" )
& ( db.scheduler_task.status != "EXPIRED" )
& ( db.scheduler_task.status != "TIMEOUT" )
& ( db.scheduler_task.status != "COMPLETED" )
).select()
if len(row3) > 0 :
res = {"message": "run already registered"}
return res
##add task to scheduller
task = scheduler.queue_task('run', [id_sequence,id_config, data_id, fuse_id]
task = scheduler.queue_task('run', [id_sequence, id_config, data_id, fuse_id]
, repeats = 1, timeout = 6000)
db.data_file[data_id] = dict(scheduler_task_id = task.id)
(filename, str) = db.sequence_file.data_file.retrieve(db.sequence_file[id_sequence].data_file)
(filename, str2) = db.sequence_file.data_file.retrieve(db.sequence_file[id_sequence].data_file)
config_name = db.config[id_config].name
patient_name = db.patient[id_patient].first_name + " " + db.patient[id_patient].last_name
......
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