Skip to content

Commit 2aefdee

Browse files
priyaramanifacebook-github-bot
authored andcommitted
List API for AWS Batch (pytorch#553)
Summary: List jobs scheduled in AWS Batch scheduler across all queues. Might support listing by queueName in the future. Pull Request resolved: pytorch#553 Test Plan: Unit tests ``` (venv38) ubuntu@ip-172-31-24-88:~/rsync/torchx$ torchx list -s aws_batch torchx 2022-07-13 00:33:16 INFO Found credentials in environment variables. aws_batch://torchx/torchx:touch-c79fsrptv.. aws_batch://torchx/torchx:sh-qpdf3z7.. aws_batch://torchx/torchx:torchx-torchserve-vcdqjk.. . . ``` Reviewed By: d4l3k Differential Revision: D37807402 Pulled By: priyaramani fbshipit-source-id: ba160f107fb6c3366d75da6cbacb1a43bb01e183
1 parent 40fa40a commit 2aefdee

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

torchx/schedulers/aws_batch_scheduler.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,33 @@ def log_iter(
577577
return iterator
578578

579579
def list(self) -> List[str]:
580-
raise NotImplementedError()
580+
# TODO: get queue name input instead of iterating over all queues?
581+
resp = self._client.describe_job_queues()
582+
queue_names = [queue["jobQueueName"] for queue in resp["jobQueues"]]
583+
all_app_ids = []
584+
for qn in queue_names:
585+
all_app_ids += self._list_by_queue(qn)
586+
return all_app_ids
587+
588+
def _list_by_queue(self, queue_name: str) -> List[str]:
589+
# By default only running jobs are listed by batch/boto client's list_jobs API
590+
# When 'filters' parameter is specified, jobs with all statuses are listed
591+
# So use AFTER_CREATED_AT filter to list jobs in all statuses
592+
# milli_seconds_after_epoch can later be used to list jobs by timeframe
593+
milli_seconds_after_epoch = "1"
594+
jobs = self._client.list_jobs(
595+
jobQueue=queue_name,
596+
filters=[
597+
{
598+
"name": "AFTER_CREATED_AT",
599+
"values": [
600+
milli_seconds_after_epoch,
601+
],
602+
},
603+
],
604+
)["jobSummaryList"]
605+
app_ids = [f"{queue_name}:{job['jobName']}" for job in jobs]
606+
return app_ids
581607

582608
def _stream_events(
583609
self,

torchx/schedulers/test/aws_batch_scheduler_test.py

+17
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,17 @@ def _mock_scheduler(self) -> AWSBatchScheduler:
514514
],
515515
}
516516

517+
scheduler._client.describe_job_queues.return_value = {
518+
"ResponseMetadata": {},
519+
"jobQueues": [
520+
{
521+
"jobQueueName": "torchx",
522+
"jobQueueArn": "arn:aws:batch:test-region:4000005:job-queue/torchx",
523+
"state": "ENABLED",
524+
},
525+
],
526+
}
527+
517528
return scheduler
518529

519530
@mock_rand()
@@ -559,6 +570,12 @@ def test_describe(self) -> None:
559570
),
560571
)
561572

573+
def test_list(self) -> None:
574+
scheduler = self._mock_scheduler()
575+
expected_app_ids = ["torchx:echo-v1r560pmwn5t3c"]
576+
app_ids = scheduler.list()
577+
self.assertEqual(app_ids, expected_app_ids)
578+
562579
def test_log_iter(self) -> None:
563580
scheduler = self._mock_scheduler()
564581
logs = scheduler.log_iter("testqueue:app-name-42", "echo", k=1, regex="foo.*")

0 commit comments

Comments
 (0)