Skip to content

Commit

Permalink
[Glue] Implement batch_get_jobs (#6241)
Browse files Browse the repository at this point in the history
  • Loading branch information
szemek authored Apr 21, 2023
1 parent a081744 commit c6b0486
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions moto/glue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,13 @@ def batch_get_crawlers(self, crawler_names: List[str]) -> List[Dict[str, Any]]:
crawlers.append(crawler.as_dict())
return crawlers

def batch_get_jobs(self, job_names: List[str]) -> List[Dict[str, Any]]:
jobs = []
for job_name in job_names:
if job_name in self.jobs:
jobs.append(self.jobs[job_name].as_dict())
return jobs


class FakeDatabase(BaseModel):
def __init__(self, database_name: str, database_input: Dict[str, Any]):
Expand Down
11 changes: 11 additions & 0 deletions moto/glue/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,5 +524,16 @@ def batch_get_crawlers(self) -> str:
}
)

def batch_get_jobs(self) -> str:
job_names = self._get_param("JobNames")
jobs = self.glue_backend.batch_get_jobs(job_names)
jobs_not_found = list(set(job_names) - set(map(lambda job: job["Name"], jobs)))
return json.dumps(
{
"Jobs": jobs,
"JobsNotFound": jobs_not_found,
}
)

def get_partition_indexes(self) -> str:
return json.dumps({"PartitionIndexDescriptorList": []})
11 changes: 11 additions & 0 deletions tests/test_glue/test_glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ def test_list_jobs_next_token_logic_does_not_create_infinite_loop():
assert not next_token


@mock_glue
def test_batch_get_jobs():
client = create_glue_client()
job_name = create_test_job(client)

response = client.batch_get_jobs(JobNames=[job_name, "job-not-found"])

assert len(response["Jobs"]) == 1
assert len(response["JobsNotFound"]) == 1


def create_glue_client():
return boto3.client("glue", region_name="us-east-1")

Expand Down

0 comments on commit c6b0486

Please sign in to comment.