Skip to content
Snippets Groups Projects
Commit 5e0f56c7 authored by Nathaniel Kofalt's avatar Nathaniel Kofalt Committed by Gunnar Schaefer
Browse files

move createJob

parent 727821c5
No related branches found
No related tags found
No related merge requests found
import logging
import datetime
log = logging.getLogger('scitran.jobs')
import base
# Creating a Job From Uploads
# The current method of util.create.job() will be removed.
# New way: the upload API handler marks the file as dirty, for later processing.
def createJob(db, jobType, containerType, containerID):
"""
@param db Reference to the database instance
@param jobType Human-friendly name of the algorithm
@param containerType Type of container ('acquisition', 'session', etc)
@param containerID ID of the container ('2', etc)
"""
if jobType != 'dcm2nii':
raise Exception('Usupported algorithm ' + jobType)
# TODO validate container exists
job = {
'state': 'pending',
'attempt': 1,
'created': datetime.datetime.now(),
'modified': datetime.datetime.now(),
'inputs': [
{
'type': 'scitran',
'location': '/',
'URI': 'TBD',
},
{
'type': 'scitran',
'location': '/script',
'URI': 'TBD',
},
],
'accents': {
'cwd': "/script",
'command': [ 'TBD' ],
'environment': { },
},
'outputs': [
{
'type': 'scitran',
'location': '/output',
'URI': 'TBD',
},
],
}
result = db.jobs.insert_one(job)
id = result.inserted_id
log.info('Running %s as job %s to process %s %s' % (jobType, str(id), containerType, containerID))
return id
......@@ -36,6 +36,69 @@ JOB_TRANSITIONS = [
def validTransition(fromState, toState):
return (fromState + " --> " + tosState) in JOB_TRANSITIONS
# Creating a Job From Uploads
# The current method of util.create.job() will be removed.
# New way: the upload API handler marks the file as dirty, for later processing.
def createJob(db, jobType, containerType, containerID):
"""
@param db Reference to the database instance
@param jobType Human-friendly name of the algorithm
@param containerType Type of container ('acquisition', 'session', etc)
@param containerID ID of the container ('2', etc)
"""
if jobType != 'dcm2nii':
raise Exception('Usupported algorithm ' + jobType)
# TODO validate container exists
job = {
'state': 'pending',
'attempt': 1,
'created': datetime.datetime.now(),
'modified': datetime.datetime.now(),
'inputs': [
{
'type': 'scitran',
'location': '/',
'URI': 'TBD',
},
{
'type': 'scitran',
'location': '/script',
'URI': 'TBD',
},
],
'accents': {
'cwd': "/script",
'command': [ 'TBD' ],
'environment': { },
},
'outputs': [
{
'type': 'scitran',
'location': '/output',
'URI': 'TBD',
},
],
}
result = db.jobs.insert_one(job)
id = result.inserted_id
log.info('Running %s as job %s to process %s %s' % (jobType, str(id), containerType, containerID))
return id
class Jobs(base.RequestHandler):
"""Provide /jobs API routes."""
......
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