Skip to content

Commit 40fa40a

Browse files
yukunlinfacebook-github-bot
authored andcommitted
Return url to job in AWS console for aws_batch scheduler (pytorch#543)
Summary: For jobs submitted to the `aws_batch` scheduler, return a URL to the job in the AWS console Pull Request resolved: pytorch#543 Test Plan: - Unit test - Submitted a job to batch, verified that the UI URL works Reviewed By: priyaramani, kurman Differential Revision: D37805026 Pulled By: d4l3k fbshipit-source-id: 5aab0d7c6b8f156dd0d6d75b0047d99e83920068
1 parent 8f85cbc commit 40fa40a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

torchx/schedulers/aws_batch_scheduler.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
for how to create a image repository.
3636
"""
3737

38+
import re
3839
import threading
3940
from dataclasses import dataclass
4041
from datetime import datetime
@@ -185,6 +186,18 @@ def _role_to_node_properties(idx: int, role: Role) -> Dict[str, object]:
185186
}
186187

187188

189+
def _job_ui_url(job_arn: str) -> Optional[str]:
190+
match = re.match(
191+
"arn:aws:batch:([a-z-0-9]+):[0-9]+:job/([a-z-0-9]+)",
192+
job_arn,
193+
)
194+
if match is None:
195+
return None
196+
region = match.group(1)
197+
job_id = match.group(2)
198+
return f"https://{region}.console.aws.amazon.com/batch/home?region={region}#jobs/mnp-job/{job_id}"
199+
200+
188201
@dataclass
189202
class BatchJob:
190203
name: str
@@ -512,6 +525,7 @@ def describe(self, app_id: str) -> Optional[DescribeAppResponse]:
512525
app_id=app_id,
513526
state=JOB_STATE[job["status"]],
514527
roles=list(roles.values()),
528+
ui_url=_job_ui_url(job["jobArn"]),
515529
)
516530

517531
def log_iter(

torchx/schedulers/test/aws_batch_scheduler_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def _mock_scheduler(self) -> AWSBatchScheduler:
408408
scheduler._client.describe_jobs.return_value = {
409409
"jobs": [
410410
{
411-
"jobArn": "thejobarn",
411+
"jobArn": "arn:aws:batch:us-west-2:495572122715:job/6afc27d7-3559-43ca-89fd-1007b6bf2546",
412412
"jobName": "app-name-42",
413413
"jobId": "6afc27d7-3559-43ca-89fd-1007b6bf2546",
414414
"jobQueue": "testqueue",
@@ -538,6 +538,10 @@ def test_describe(self) -> None:
538538
self.assertIsNotNone(status)
539539
self.assertEqual(status.state, specs.AppState.SUCCEEDED)
540540
self.assertEqual(status.app_id, "testqueue:app-name-42")
541+
self.assertEqual(
542+
status.ui_url,
543+
"https://us-west-2.console.aws.amazon.com/batch/home?region=us-west-2#jobs/mnp-job/6afc27d7-3559-43ca-89fd-1007b6bf2546",
544+
)
541545
self.assertEqual(
542546
status.roles[0],
543547
specs.Role(

0 commit comments

Comments
 (0)