22 from collection import *
29 # Set up Arvados logging based on the user's configuration.
30 # All Arvados code should log under the arvados hierarchy.
31 log_handler = logging.StreamHandler()
32 log_handler.setFormatter(logging.Formatter(
33 '%(asctime)s %(name)s[%(process)d] %(levelname)s: %(message)s',
35 logger = logging.getLogger('arvados')
36 logger.addHandler(log_handler)
37 logger.setLevel(logging.DEBUG if config.get('ARVADOS_DEBUG')
40 def task_set_output(self,s):
41 api('v1').job_tasks().update(uuid=self['uuid'],
53 t = api('v1').job_tasks().get(uuid=os.environ['TASK_UUID']).execute()
54 t = UserDict.UserDict(t)
55 t.set_output = types.MethodType(task_set_output, t)
56 t.tmpdir = os.environ['TASK_WORK']
65 t = api('v1').jobs().get(uuid=os.environ['JOB_UUID']).execute()
66 t = UserDict.UserDict(t)
67 t.tmpdir = os.environ['JOB_WORK']
71 def getjobparam(*args):
72 return current_job()['script_parameters'].get(*args)
74 def get_job_param_mount(*args):
75 return os.path.join(os.environ['TASK_KEEPMOUNT'], current_job()['script_parameters'].get(*args))
77 def get_task_param_mount(*args):
78 return os.path.join(os.environ['TASK_KEEPMOUNT'], current_task()['parameters'].get(*args))
80 class JobTask(object):
81 def __init__(self, parameters=dict(), runtime_constraints=dict()):
82 print "init jobtask %s %s" % (parameters, runtime_constraints)
86 def one_task_per_input_file(if_sequence=0, and_end_task=True, input_as_path=False):
87 if if_sequence != current_task()['sequence']:
89 job_input = current_job()['script_parameters']['input']
90 cr = CollectionReader(job_input)
92 for s in cr.all_streams():
93 for f in s.all_files():
95 task_input = os.path.join(job_input, s.name(), f.name())
97 task_input = f.as_manifest()
99 'job_uuid': current_job()['uuid'],
100 'created_by_job_task_uuid': current_task()['uuid'],
101 'sequence': if_sequence + 1,
106 api('v1').job_tasks().create(body=new_task_attrs).execute()
108 api('v1').job_tasks().update(uuid=current_task()['uuid'],
109 body={'success':True}
114 def one_task_per_input_stream(if_sequence=0, and_end_task=True):
115 if if_sequence != current_task()['sequence']:
117 job_input = current_job()['script_parameters']['input']
118 cr = CollectionReader(job_input)
119 for s in cr.all_streams():
120 task_input = s.tokens()
122 'job_uuid': current_job()['uuid'],
123 'created_by_job_task_uuid': current_task()['uuid'],
124 'sequence': if_sequence + 1,
129 api('v1').job_tasks().create(body=new_task_attrs).execute()
131 api('v1').job_tasks().update(uuid=current_task()['uuid'],
132 body={'success':True}