Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelvin-M committed Mar 4, 2020
1 parent 0d47a58 commit 84c40c6
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions backend/substrapp/tasks/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,13 @@ def fetch_model(parent_tuple_type, authorized_types, input_model, directory):
raise TasksError(f'Traintuple: invalid input model: type={tuple_type}')


def prepare_traintuple_input_models(directory, tuple_):
"""Get traintuple input models content."""
input_models = tuple_.get('inModels')
if not input_models:
return

authorized_types = (AGGREGATETUPLE_TYPE, TRAINTUPLE_TYPE)
def fetch_models(tuple_type, authorized_types, input_models, directory):

models = []

for input_model in input_models:
proc = ExceptionThread(target=fetch_model,
args=(TRAINTUPLE_TYPE, authorized_types, input_model, directory))
args=(tuple_type, authorized_types, input_model, directory))
models.append(proc)
proc.start()

Expand All @@ -227,33 +222,26 @@ def prepare_traintuple_input_models(directory, tuple_):
raise Exception(exceptions)


def prepare_aggregatetuple_input_models(directory, tuple_):
"""Get aggregatetuple input models content."""
def prepare_traintuple_input_models(directory, tuple_):
"""Get traintuple input models content."""
input_models = tuple_.get('inModels')
if not input_models:
return

authorized_types = (AGGREGATETUPLE_TYPE, TRAINTUPLE_TYPE, COMPOSITE_TRAINTUPLE_TYPE)
models = []
authorized_types = (AGGREGATETUPLE_TYPE, TRAINTUPLE_TYPE)

for input_model in input_models:
proc = ExceptionThread(target=fetch_model,
args=(AGGREGATETUPLE_TYPE, authorized_types, input_model, directory))
models.append(proc)
proc.start()
fetch_models(TRAINTUPLE_TYPE, authorized_types, input_models, directory)

for proc in models:
proc.join()

exceptions = []
def prepare_aggregatetuple_input_models(directory, tuple_):
"""Get aggregatetuple input models content."""
input_models = tuple_.get('inModels')
if not input_models:
return

for proc in models:
if hasattr(proc, "_exception"):
exceptions.append(proc._exception)
logger.exception(proc._exception)
else:
if exceptions:
raise Exception(exceptions)
authorized_types = (AGGREGATETUPLE_TYPE, TRAINTUPLE_TYPE, COMPOSITE_TRAINTUPLE_TYPE)

fetch_models(AGGREGATETUPLE_TYPE, authorized_types, input_models, directory)


def prepare_composite_traintuple_input_models(directory, tuple_):
Expand Down

0 comments on commit 84c40c6

Please sign in to comment.