Skip to content
Snippets Groups Projects
Commit b54eaced authored by Nathaniel Kofalt's avatar Nathaniel Kofalt
Browse files

Port #69 to master

parent 6c8b0fc6
No related branches found
No related tags found
No related merge requests found
......@@ -31,23 +31,22 @@ JOB_STATES_ALLOWED_MUTATE = [
]
JOB_TRANSITIONS = [
"pending --> running",
"running --> failed",
"running --> complete",
'pending --> running',
'running --> failed',
'running --> complete',
]
def valid_transition(from_state, to_state):
return (from_state + " --> " + to_state) in JOB_TRANSITIONS or from_state == to_state
return (from_state + ' --> ' + to_state) in JOB_TRANSITIONS or from_state == to_state
ALGORITHMS = [
"dcm2nii"
'dcm2nii'
]
# A FileInput tuple holds all the details of a scitran file that needed to use that as an input a formula.
FileInput = namedtuple('input', ['container_type', 'container_id', 'filename', 'filehash'])
# Convert a dictionary to a FileInput
# REVIEW: less irritating conversion?
def convert_to_fileinput(d):
return FileInput(
container_type= d['container_type'],
......@@ -141,25 +140,26 @@ def retry_job(db, j, force=False):
log.info('permanently failed job %s (after %d attempts)' % (j['_id'], j['attempt']))
def generate_formula(i):
def generate_formula(algorithm_id, i):
"""
Given an intent, generates a formula to execute a job.
Parameters
----------
i: map
A job's intent that holds everything needed to generate a formula.
algorithm_id: string
Human-friendly unique name of the algorithm
i: FileInput
The input to be used by this job
"""
if i['algorithm_id'] not in ALGORITHMS:
if algorithm_id not in ALGORITHMS:
raise Exception('Usupported algorithm ' + algorithm_id)
# Currently hard-coded for a single algorithm: dcm2nii
f = {
'inputs': [
{
'type': 'file',
'uri': '/opt/flywheel-temp/dcm_convert-0.1.1.tar',
'uri': '/nope.txt',
'location': '/',
},
{
......@@ -169,7 +169,7 @@ def generate_formula(i):
}
],
'transform': {
'command': ['bash', '-c', 'mkdir /output; /scripts/run /input/' + i['filename'] + ' /output/' + i['filename'].split('_')[0] ],
'command': [ 'echo', 'No command specified for ' + algorithm_id],
'env': { },
'dir': "/",
},
......@@ -183,6 +183,16 @@ def generate_formula(i):
],
}
if algorithm_id == 'dcm2nii':
f['inputs'][0]['uri'] = '/opt/flywheel-temp/dcm_convert-0.1.1.tar'
f['transform']['command'] = ['bash', '-c', 'mkdir /output; /scripts/run /input/' + i['filename'] + ' /output/' + i['filename'].split('_')[0]]
elif algorithm_id == 'qa':
f['inputs'][0]['uri'] = '/opt/flywheel-temp/qa-report-fmri-0.0.2.tar'
f['transform']['command'] = ['bash', '-c', 'mkdir /output; /scripts/run; exit 0']
else:
raise Exception('Command for algorithm ' + algorithm_id + ' not specified')
return f
class Jobs(base.RequestHandler):
......@@ -238,7 +248,7 @@ class Jobs(base.RequestHandler):
'_id': result['_id']
},
{ '$set': {
'request': generate_formula(result['intent'])}
'request': generate_formula(result['algorithm_id'], result['input'])}
},
return_document=pymongo.collection.ReturnDocument.AFTER
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment