22 from collection import *
28 def task_set_output(self,s):
29 api('v1').job_tasks().update(uuid=self['uuid'],
41 t = api('v1').job_tasks().get(uuid=os.environ['TASK_UUID']).execute()
42 t = UserDict.UserDict(t)
43 t.set_output = types.MethodType(task_set_output, t)
44 t.tmpdir = os.environ['TASK_WORK']
53 t = api('v1').jobs().get(uuid=os.environ['JOB_UUID']).execute()
54 t = UserDict.UserDict(t)
55 t.tmpdir = os.environ['JOB_WORK']
59 def getjobparam(*args):
60 return current_job()['script_parameters'].get(*args)
62 def get_job_param_mount(*args):
63 return os.path.join(os.environ['TASK_KEEPMOUNT'], current_job()['script_parameters'].get(*args))
65 def get_task_param_mount(*args):
66 return os.path.join(os.environ['TASK_KEEPMOUNT'], current_task()['parameters'].get(*args))
68 class JobTask(object):
69 def __init__(self, parameters=dict(), runtime_constraints=dict()):
70 print "init jobtask %s %s" % (parameters, runtime_constraints)
74 def one_task_per_input_file(if_sequence=0, and_end_task=True, input_as_path=False):
75 if if_sequence != current_task()['sequence']:
77 job_input = current_job()['script_parameters']['input']
78 cr = CollectionReader(job_input)
79 for s in cr.all_streams():
80 for f in s.all_files():
82 task_input = os.path.join(job_input, s.name(), f.name())
84 task_input = f.as_manifest()
86 'job_uuid': current_job()['uuid'],
87 'created_by_job_task_uuid': current_task()['uuid'],
88 'sequence': if_sequence + 1,
93 api('v1').job_tasks().create(body=new_task_attrs).execute()
95 api('v1').job_tasks().update(uuid=current_task()['uuid'],
101 def one_task_per_input_stream(if_sequence=0, and_end_task=True):
102 if if_sequence != current_task()['sequence']:
104 job_input = current_job()['script_parameters']['input']
105 cr = CollectionReader(job_input)
106 for s in cr.all_streams():
107 task_input = s.tokens()
109 'job_uuid': current_job()['uuid'],
110 'created_by_job_task_uuid': current_task()['uuid'],
111 'sequence': if_sequence + 1,
116 api('v1').job_tasks().create(body=new_task_attrs).execute()
118 api('v1').job_tasks().update(uuid=current_task()['uuid'],
119 body={'success':True}