Skip to content
This repository was archived by the owner on Mar 13, 2026. It is now read-only.

Commit 7cae52a

Browse files
authored
DO-1383 Fix logging (#6)
1 parent 027b1ac commit 7cae52a

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/app.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from flask import Flask, abort, request
55

66
from const import GithubHeaders, LOGGING_CONFIG
7-
from utils import get_message, parse_datetime
7+
from utils import parse_datetime
88

99
dictConfig(LOGGING_CONFIG)
1010

@@ -45,7 +45,10 @@ def process_workflow_job():
4545
if action == "queued":
4646
# add to memory as timestamp
4747
jobs[job_id] = int(time_start.timestamp())
48-
msg = get_message(action, repository, job_id, workflow)
48+
msg = (
49+
f"action={action} repository={repository} job_id={job_id}"
50+
f' workflow="{workflow}"'
51+
)
4952

5053
elif action == "in_progress":
5154
job_requested = jobs.get(job_id)
@@ -54,7 +57,10 @@ def process_workflow_job():
5457
time_to_start = 0
5558
else:
5659
time_to_start = (time_start - datetime.fromtimestamp(job_requested)).seconds
57-
msg = get_message(action, repository, job_id, time_to_start, workflow)
60+
msg = (
61+
f"action={action} repository={repository} job_id={job_id}"
62+
f' workflow="{workflow}" time_to_start={time_to_start}'
63+
)
5864

5965
elif action == "completed":
6066
job_requested = jobs.get(job_id)
@@ -67,7 +73,10 @@ def process_workflow_job():
6773
).seconds
6874
# delete from memory
6975
del jobs[job_id]
70-
msg = get_message(action, repository, job_id, time_to_finish, workflow)
76+
msg = (
77+
f"action={action} repository={repository} job_id={job_id}"
78+
f' workflow="{workflow}" time_to_finish={time_to_finish}'
79+
)
7180
else:
7281
app.logger.warning(f"Unknown action {action}, removing from memory")
7382
if job_id in jobs:

src/utils.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
from datetime import datetime
22

3+
34
def parse_datetime(date: str) -> datetime:
4-
""" Parse GitHub date to object """
5+
"""Parse GitHub date to object"""
56
exp = "%Y-%m-%dT%H:%M:%SZ"
67
return datetime.strptime(date, exp)
7-
8-
9-
def get_message(*args) -> str:
10-
""" Return variables as string logfmt """
11-
msg = list()
12-
for variable in args:
13-
var_name = f"{variable=}".split("=")[1]
14-
msg.append(f'{var_name}="{variable}"')
15-
return " ".join(msg)

0 commit comments

Comments
 (0)