Skip to content

Commit

Permalink
Format and linting code
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-winkler committed Oct 25, 2024
1 parent 9f0fb80 commit 4706c7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
9 changes: 7 additions & 2 deletions src/worker/common/log_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
from worker.common.config import Config


def configure_logging():
logging.basicConfig(
level=__get_log_level(Config.LOG_LEVEL),
Expand All @@ -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)
Expand All @@ -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}
Expand Down
37 changes: 16 additions & 21 deletions src/worker/sentinel/tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from worker.common.log_utils import configure_logging, log_with_job, log_variable

configure_logging()
Expand All @@ -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()
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 4706c7c

Please sign in to comment.