Skip to content

Commit be58cc8

Browse files
committed
making a helper method for clickable log link
1 parent ad29604 commit be58cc8

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/workbench/scripts/ml_pipeline_launcher.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ def get_batch_role_arn() -> str:
2727
return f"arn:aws:iam::{account_id}:role/Workbench-BatchRole"
2828

2929

30+
def _log_cloudwatch_link(job: dict, message_prefix: str = "View logs") -> None:
31+
"""
32+
Helper method to log CloudWatch logs link with clickable URL and full URL display.
33+
34+
Args:
35+
job: Batch job description dictionary
36+
message_prefix: Prefix for the log message (default: "View logs")
37+
"""
38+
log_stream = job.get("container", {}).get("logStreamName")
39+
logs_url = get_cloudwatch_logs_url(log_group="/aws/batch/job", log_stream=log_stream)
40+
if logs_url:
41+
clickable_url = f"\033]8;;{logs_url}\033\\{logs_url}\033]8;;\033\\"
42+
log.info(f"{message_prefix}: {clickable_url}")
43+
else:
44+
log.info("Check AWS Batch console for logs")
45+
46+
3047
def run_batch_job(script_path: str, size: str = "small") -> int:
3148
"""
3249
Submit and monitor an AWS Batch job for ML pipeline execution.
@@ -84,18 +101,9 @@ def run_batch_job(script_path: str, size: str = "small") -> int:
84101

85102
# Disconnect after 2 minutes of running
86103
if status == "RUNNING" and running_start and (time.time() - running_start >= 120):
87-
log_stream = job.get("container", {}).get("logStreamName")
88-
logs_url = get_cloudwatch_logs_url(log_group="/aws/batch/job", log_stream=log_stream)
89-
90-
log.info("\n" + "=" * 70)
91104
log.info("✅ ML Pipeline is running successfully!")
92-
if logs_url:
93-
clickable_url = f"\033]8;;{logs_url}\033\\View CloudWatch Logs\033]8;;\033\\"
94-
log.info(f"📊 Monitor logs: {clickable_url}")
95-
else:
96-
log.info("Check AWS Batch console for logs")
105+
_log_cloudwatch_link(job, "📊 Monitor logs")
97106
log.info(f"Job ID: {job_id}")
98-
log.info("=" * 70)
99107
return 0
100108

101109
# Handle completion
@@ -107,11 +115,7 @@ def run_batch_job(script_path: str, size: str = "small") -> int:
107115
else f"Job failed: {job.get('statusReason', 'Unknown')}"
108116
)
109117
log.info(msg) if status == "SUCCEEDED" else log.error(msg)
110-
111-
log_stream = job.get("container", {}).get("logStreamName")
112-
if logs_url := get_cloudwatch_logs_url(log_group="/aws/batch/job", log_stream=log_stream):
113-
clickable_url = f"\033]8;;{logs_url}\033\\{logs_url}\033]8;;\033\\"
114-
log.info(f"View logs: {clickable_url}")
118+
_log_cloudwatch_link(job)
115119
return exit_code
116120

117121
time.sleep(10)

0 commit comments

Comments
 (0)