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.join(os.environ['TASK_KEEPMOUNT'], current_job()['script_parameters'].get(*args))
65 def get_task_param_mount(*args):
66 return os.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):
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():
81 task_input = f.as_manifest()
83 'job_uuid': current_job()['uuid'],
84 'created_by_job_task_uuid': current_task()['uuid'],
85 'sequence': if_sequence + 1,
90 api('v1').job_tasks().create(body=new_task_attrs).execute()
92 api('v1').job_tasks().update(uuid=current_task()['uuid'],
98 def one_task_per_input_stream(if_sequence=0, and_end_task=True):
99 if if_sequence != current_task()['sequence']:
101 job_input = current_job()['script_parameters']['input']
102 cr = CollectionReader(job_input)
103 for s in cr.all_streams():
104 task_input = s.tokens()
106 'job_uuid': current_job()['uuid'],
107 'created_by_job_task_uuid': current_task()['uuid'],
108 'sequence': if_sequence + 1,
113 api('v1').job_tasks().create(body=new_task_attrs).execute()
115 api('v1').job_tasks().update(uuid=current_task()['uuid'],
116 body={'success':True}