diff --git a/src/worker/common/log_utils.py b/src/worker/common/log_utils.py index 919dda2..42374e8 100644 --- a/src/worker/common/log_utils.py +++ b/src/worker/common/log_utils.py @@ -1,6 +1,7 @@ import logging from worker.common.config import Config + def configure_logging(): logging.basicConfig( level=__get_log_level(Config.LOG_LEVEL), @@ -18,15 +19,17 @@ def log_with_job(message, job=None, log_level="info", **kwargs): else: log_function(message, **kwargs) + def log_variable(variable, job=None, log_level="info", **kwargs): log_function = __get_log_function(log_level) message = f"[TASK_VARIABLE] name={variable.name} value='{variable.value}' type={variable.type}" - if job is not None: + if job is not None: log_with_job(message=message, job=job) else: log_function(msg=message) + def log_with_context(message, context=None, log_level="info", **kwargs): context = context if context is not None else {} log_function = __get_log_function(log_level) @@ -46,9 +49,11 @@ def __get_log_context_prefix(context): log_context_prefix += f"[{k}:{v}]" return log_context_prefix + def __get_log_level(log_level: str): switcher = {"info": logging.INFO, "debug": logging.DEBUG, "warning": logging.WARNING, "error": logging.ERROR} - return switcher.get(log_level.lower(), logging.INFO) + return switcher.get(log_level.lower(), logging.INFO) + def __get_log_function(log_level: str): switcher = {"info": logging.info, "debug": logging.debug, "warning": logging.warning, "error": logging.error} diff --git a/src/worker/sentinel/tasks.py b/src/worker/sentinel/tasks.py index 90ee7c6..3cc5abd 100644 --- a/src/worker/sentinel/tasks.py +++ b/src/worker/sentinel/tasks.py @@ -1,4 +1,3 @@ -import json from worker.common.log_utils import configure_logging, log_with_job, log_variable configure_logging() @@ -9,18 +8,10 @@ def sentinel_discover_data(job, worker_result_builder): # discovering scenes scenes = [] - scene1 = { - "scene": { - "name": "scene1" - } - } - scene2 = { - "scene": { - "name": "scene2" - } - } + scene1 = {"scene": {"name": "scene1"}} + # scene2 = {"scene": {"name": "scene2"}} scenes.append(scene1) - #scenes.append(scene2) + # scenes.append(scene2) # build result result = worker_result_builder.success() @@ -31,28 +22,31 @@ def sentinel_discover_data(job, worker_result_builder): return result + def sentinel_order_data(job, worker_result_builder): log_with_job(message="Ordering data ...", job=job) result = worker_result_builder.success() return result + def sentinel_download_data(job, worker_result_builder): log_with_job(message="Downloading data ...", job=job) # get job variables for v in job.variables: log_variable(variable=v, job=job, log_level="info") - + result = worker_result_builder.success() return result + def sentinel_unzip(job, worker_result_builder): log_with_job(message="Unzipping ...", job=job) # get job variables for v in job.variables: log_variable(variable=v, job=job, log_level="info") - + result = worker_result_builder.success() return result @@ -70,12 +64,12 @@ def sentinel_check_integrity(job, worker_result_builder): scene = job_vars["scene"] log_with_job(f"Input variable: scene={scene}") - - scene['collection'] = "sentinel-1" - #scene['collection'] = "" + + scene["collection"] = "sentinel-1" + # scene['collection'] = "" log_with_job(f"Output variable: scene={scene}") result = worker_result_builder.success() - result.variable_string(name="collection", value=scene['collection']) + result.variable_string(name="collection", value=scene["collection"]) return result @@ -86,7 +80,7 @@ def sentinel_extract_metadata(job, worker_result_builder): # get job variables for v in job.variables: log_variable(variable=v, job=job, log_level="info") - + result = worker_result_builder.success() return result @@ -97,17 +91,18 @@ def sentinel_register_metadata(job, worker_result_builder): # get job variables for v in job.variables: log_variable(variable=v, job=job, log_level="info") - + result = worker_result_builder.success() return result + def sentinel_inventory_update(job, worker_result_builder): log_with_job(message="Updating inventory ...", job=job) # get job variables for v in job.variables: log_variable(variable=v, job=job, log_level="info") - + result = worker_result_builder.success() return result