Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions saagieapi/jobs/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ def create(
emails: List = None,
status_list: List = None,
source_url: str = "",
docker_info: Dict = None,
) -> Dict:
"""Create job in given project

Expand Down Expand Up @@ -635,6 +636,9 @@ def create(
"RUNNING", "FAILED", "KILLED", "KILLING", "SUCCEEDED", "UNKNOWN", "AWAITING", "SKIPPED"
source_url: str, optional
URL of the source code used for the job (link to the commit for example)
docker_info: dict (optional)
Docker information for the job
Example: {"image": "my_image", "dockerCredentialsId": "MY_CREDENTIALS_ID"}

Returns
-------
Expand Down Expand Up @@ -730,6 +734,9 @@ def create(
if source_url:
params["sourceUrl"] = source_url

if docker_info:
params["dockerInfo"] = docker_info

result = self.__launch_request(file, GQL_CREATE_JOB, params)
logging.info("✅ Job [%s] successfully created", job_name)
return result
Expand Down Expand Up @@ -877,6 +884,7 @@ def upgrade(
extra_technology: str = None,
extra_technology_version: str = None,
source_url: str = "",
docker_info: dict = None,
) -> Dict:
"""Upgrade a job

Expand All @@ -903,6 +911,9 @@ def upgrade(
Version of the extra technology. Leave to None when not needed
source_url: str (optional)
URL of the source code used for the job (link to the commit for example)
docker_info: dict (optional)
Docker information for the job
Example: {"image": "my_image", "dockerCredentialsId": "MY_CREDENTIALS_ID"}

Returns
-------
Expand Down Expand Up @@ -957,6 +968,7 @@ def upgrade(
"runtimeVersion": runtime_version or job_info["versions"][0]["runtimeVersion"],
"commandLine": command_line or job_info["versions"][0]["commandLine"],
"usePreviousArtifact": bool(use_previous_artifact and job_info["versions"][0]["packageInfo"]),
"dockerInfo": docker_info or job_info["versions"][0]["dockerInfo"],
}

# Add extra technology parameter if needed
Expand Down Expand Up @@ -1066,6 +1078,7 @@ def create_or_upgrade(
emails: List = None,
status_list: List = None,
source_url: str = "",
docker_info: dict = None,
) -> Dict:
"""Create or upgrade a job

Expand Down Expand Up @@ -1112,6 +1125,9 @@ def create_or_upgrade(
Status list
source_url: str (optional)
URL of the source code used for the job (link to the commit for example)
docker_info: dict (optional)
Docker information for the job
Example: {"image": "my_image", "dockerCredentialsId": "MY_CREDENTIALS_ID"}

Returns
-------
Expand Down Expand Up @@ -1141,6 +1157,7 @@ def create_or_upgrade(
... emails=['email1@saagie.io', 'email2@saagie.io'],
... status_list=["FAILED", "KILLED"],
... source_url="",
... docker_info=None
... )
{
"data":{
Expand Down Expand Up @@ -1175,6 +1192,7 @@ def create_or_upgrade(
extra_technology=extra_technology,
extra_technology_version=extra_technology_version,
source_url=source_url,
docker_info=docker_info,
)["data"]["addJobVersion"]
}

Expand Down Expand Up @@ -1214,6 +1232,7 @@ def create_or_upgrade(
"emails": emails,
"status_list": status_list,
"source_url": source_url,
"docker_info": docker_info,
}.items()
if v is not None # Remove None values from the dict
}
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/jobs_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def test_create_job(self, saagie_api_mock):
"status_list": ["FAILED", "KILLED"],
"cron_scheduling": "0 0 * * *",
"schedule_timezone": "Europe/Paris",
"docker_info": {"image": "my_image", "dockerCredentialsId": "MY_CREDENTIAL_UUID"},
}
# Patch the self.__launch_request method to avoid calling the API
with patch.object(instance, "_Jobs__launch_request") as launch_request:
Expand Down Expand Up @@ -288,6 +289,7 @@ def test_create_job_with_extra_techno(self, saagie_api_mock):
"release_note": "Initial version",
"extra_technology": "python",
"extra_technology_version": "3.9",
"docker_info": {"image": "my_image", "dockerCredentialsId": "MY_CREDENTIAL_UUID"},
}

with patch.object(instance, "_Jobs__launch_request") as launch_request:
Expand Down Expand Up @@ -579,6 +581,7 @@ def test_upgrade_job(self, saagie_api_mock, caplog):
"job_id": "60f46dce-c869-40c3-a2e5-1d7765a806db",
"file": "/tmp/my_file.py",
"source_url": "http://my.super.source.url",
"docker_info": {"image": "my_image", "dockerCredentialsId": "MY_CREDENTIAL_UUID"},
}
# Mock the return value
return_value = {"data": {"addJobVersion": {"number": 2, "__typename": "JobVersion"}}}
Expand Down Expand Up @@ -655,6 +658,7 @@ def test_upgrade_job_with_extra_techno(self, saagie_api_mock):
"source_url": "http://my.super.source.url",
"extra_technology": "python",
"extra_technology_version": "3.9",
"docker_info": {"image": "my_image", "dockerCredentialsId": "MY_CREDENTIAL_UUID"},
}
# Mock the return value
return_value = {"data": {"addJobVersion": {"number": 2, "__typename": "JobVersion"}}}
Expand Down