Skip to content
Snippets Groups Projects
Commit 1880ceb0 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

TMSS-272: fixed concurrency

parent 4e103455
No related branches found
No related tags found
1 merge request!213Resolve TMSS-272
......@@ -27,23 +27,23 @@ def populate_schemas(schema_dir: str=None, templates_filename: str=None):
if templates_filename is None:
templates_filename = 'templates.json'
with TMSSsession.create_from_dbcreds_for_ldap() as client:
templates_filepath = os.path.join(schema_dir, templates_filename)
logger.info("Reading templates in: %s", templates_filepath)
with open(templates_filepath) as templates_file:
templates = json.loads(templates_file.read())
templates_filepath = os.path.join(schema_dir, templates_filename)
logger.info("Reading templates in: %s", templates_filepath)
with open(templates_filepath) as templates_file:
templates = json.loads(templates_file.read())
def upload_template(template):
try:
with open(os.path.join(schema_dir, template.pop('file_name'))) as schema_file:
try:
json_schema = json.loads(schema_file.read())
def upload_template(template):
try:
with open(os.path.join(schema_dir, template.pop('file_name'))) as schema_file:
try:
json_schema = json.loads(schema_file.read())
template_path = template.pop('template')
name = template.pop('name', json_schema.get('title', '<no name>'))
description = template.pop('description', json_schema.get('description', '<no description>'))
version = template.pop('version', '1')
template_path = template.pop('template')
name = template.pop('name', json_schema.get('title', '<no name>'))
description = template.pop('description', json_schema.get('description', '<no description>'))
version = template.pop('version', '1')
with TMSSsession.create_from_dbcreds_for_ldap() as client:
if template_path == 'subtask_template' and 'type' in template:
# override plain-text type by its url
template['type'] = client.get_path_as_json_object('subtask_type/'+template.pop('type'))['url']
......@@ -67,10 +67,10 @@ def populate_schemas(schema_dir: str=None, templates_filename: str=None):
description=description,
version=version,
**template)
except Exception as e:
logger.error(e)
except Exception as e:
logger.error(e)
except Exception as e:
logger.error(e)
except Exception as e:
logger.error(e)
with futures.ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
executor.map(upload_template, templates)
with futures.ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
executor.map(upload_template, templates)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment