Coverage for src/container_collection/batch/make_batch_job.py: 100%
8 statements
« prev ^ index » next coverage.py v7.1.0, created at 2024-09-25 18:23 +0000
« prev ^ index » next coverage.py v7.1.0, created at 2024-09-25 18:23 +0000
1from __future__ import annotations
4def make_batch_job(
5 name: str,
6 image: str,
7 vcpus: int,
8 memory: int,
9 environment: list[dict[str, str]] | None = None,
10 job_role_arn: str | None = None,
11) -> dict:
12 """
13 Create batch job definition.
15 Docker images on the Docker Hub registry are available by default, and can
16 be specified using ``image:tag``. Otherwise, use ``repository/image:tag``.
18 Environment variables are passed as key-value pairs using the following
19 structure:
21 .. code-block:: python
23 [
24 { "name" : "envName1", "value" : "envValue1" },
25 { "name" : "envName2", "value" : "envValue2" },
26 ...
27 ]
29 Parameters
30 ----------
31 name
32 Job definition name.
33 image
34 Docker image.
35 vcpus
36 Number of vCPUs to reserve for the container.
37 memory
38 Memory limit available to the container
39 environment
40 List of environment variables as key-value pairs.
41 job_role_arn
42 ARN for IAM role for the job container.
44 Returns
45 -------
46 :
47 Job definition.
48 """
50 container_properties = {
51 "image": image,
52 "vcpus": vcpus,
53 "memory": memory,
54 }
56 if environment is not None:
57 container_properties["environment"] = environment
59 if job_role_arn is not None:
60 container_properties["jobRoleArn"] = job_role_arn
62 return {
63 "jobDefinitionName": name,
64 "type": "container",
65 "containerProperties": container_properties,
66 }