21 EMPTY_BLOCK_LOCATOR = 'd41d8cd98f00b204e9800998ecf8427e+0'
25 from collection import *
30 class SyntaxError(Exception):
32 class AssertionError(Exception):
34 class NotFoundError(Exception):
36 class CommandFailedError(Exception):
38 class KeepWriteError(Exception):
40 class NotImplementedError(Exception):
43 def task_set_output(self,s):
44 api('v1').job_tasks().update(uuid=self['uuid'],
56 t = api('v1').job_tasks().get(uuid=os.environ['TASK_UUID']).execute()
57 t = UserDict.UserDict(t)
58 t.set_output = types.MethodType(task_set_output, t)
59 t.tmpdir = os.environ['TASK_WORK']
68 t = api('v1').jobs().get(uuid=os.environ['JOB_UUID']).execute()
69 t = UserDict.UserDict(t)
70 t.tmpdir = os.environ['JOB_WORK']
74 def getjobparam(*args):
75 return current_job()['script_parameters'].get(*args)
77 class JobTask(object):
78 def __init__(self, parameters=dict(), runtime_constraints=dict()):
79 print "init jobtask %s %s" % (parameters, runtime_constraints)
83 def one_task_per_input_file(if_sequence=0, and_end_task=True):
84 if if_sequence != current_task()['sequence']:
86 job_input = current_job()['script_parameters']['input']
87 cr = CollectionReader(job_input)
88 for s in cr.all_streams():
89 for f in s.all_files():
90 task_input = f.as_manifest()
92 'job_uuid': current_job()['uuid'],
93 'created_by_job_task_uuid': current_task()['uuid'],
94 'sequence': if_sequence + 1,
99 api('v1').job_tasks().create(body=new_task_attrs).execute()
101 api('v1').job_tasks().update(uuid=current_task()['uuid'],
102 body={'success':True}
107 def one_task_per_input_stream(if_sequence=0, and_end_task=True):
108 if if_sequence != current_task()['sequence']:
110 job_input = current_job()['script_parameters']['input']
111 cr = CollectionReader(job_input)
112 for s in cr.all_streams():
113 task_input = s.tokens()
115 'job_uuid': current_job()['uuid'],
116 'created_by_job_task_uuid': current_task()['uuid'],
117 'sequence': if_sequence + 1,
122 api('v1').job_tasks().create(body=new_task_attrs).execute()
124 api('v1').job_tasks().update(uuid=current_task()['uuid'],
125 body={'success':True}