-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: UN-1983 BE Enhancements for file centric logging #1157
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,25 @@ def is_json(string: str) -> bool: | |
return False | ||
return True | ||
|
||
# TODO: Use from SDK | ||
@staticmethod | ||
def pretty_file_size(num: float, suffix: str = "B") -> str: | ||
"""Gets the human readable size for a file, | ||
|
||
Args: | ||
num (int): Size in bytes to parse | ||
suffix (str, optional): _description_. Defaults to "B". | ||
|
||
Returns: | ||
str: Human readable size | ||
""" | ||
for unit in ("", "K", "M", "G", "T"): | ||
if abs(num) < 1024.0: | ||
# return f"{num:3.1f} {unit}{suffix}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove commented line |
||
return f"{num:.2f} {unit}{suffix}" | ||
num /= 1024.0 | ||
return f"{num:.2f} {suffix}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually we should increase the units to |
||
|
||
|
||
class ModelEnum(Enum): | ||
@classmethod | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,8 @@ def get_successful_files(self, obj: WorkflowExecution) -> int: | |
def get_failed_files(self, obj: WorkflowExecution) -> int: | ||
"""Return the count of failed executed files""" | ||
return obj.file_executions.filter(status=ExecutionStatus.ERROR).count() | ||
|
||
def to_representation(self, obj: WorkflowExecution): | ||
data = super().to_representation(obj) | ||
data["execution_time"] = obj.pretty_execution_time | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of this please try adding |
||
return data |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,21 +4,39 @@ | |
from workflow_manager.file_execution.models import ( | ||
WorkflowFileExecution as FileExecution, | ||
) | ||
from workflow_manager.workflow_v2.enums import ExecutionStatus | ||
|
||
INIT_STATUS_MSG = "Waiting for a worker to pick up file's execution..." | ||
|
||
DEFAULT_STATUS_MSG = ( | ||
"No status message available, please check again after a few minutes." | ||
) | ||
|
||
|
||
class FileCentricExecutionSerializer(serializers.ModelSerializer): | ||
latest_log = serializers.SerializerMethodField() | ||
status_msg = serializers.SerializerMethodField() | ||
|
||
class Meta: | ||
model = FileExecution | ||
exclude = ["file_hash"] | ||
|
||
def get_latest_log(self, obj: FileExecution) -> Optional[dict[str, any]]: | ||
def get_status_msg(self, obj: FileExecution) -> Optional[dict[str, any]]: | ||
if obj.status in [ExecutionStatus.PENDING, ExecutionStatus.QUEUED]: | ||
return INIT_STATUS_MSG | ||
|
||
latest_log = ( | ||
obj.execution_logs.exclude(data__level__in=["DEBUG", "WARN"]) | ||
.order_by("-event_time") | ||
.first() | ||
) | ||
return ( | ||
latest_log.data["log"] if latest_log and "log" in latest_log.data else None | ||
latest_log.data["log"] | ||
if latest_log and "log" in latest_log.data | ||
else DEFAULT_STATUS_MSG | ||
Comment on lines
+23
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This query/method seems to be resource-intensive. Have we analyzed its performance ? (we can use EXPLAIN or some kind of query analyzer) What is the exact requirement for this query, is there any other aproach to get same requirements?" |
||
) | ||
|
||
def to_representation(self, obj: FileExecution): | ||
data = super().to_representation(obj) | ||
data["file_size"] = obj.pretty_file_size | ||
data["execution_time"] = obj.pretty_execution_time | ||
return data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What will be the possible value of suffix other than
B
?