-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(samples): Adding samples for list and get tasks (#50)
* Fixing tests * docs(samples): Adding samples for list tasks and get task Co-authored-by: Anthonios Partheniou <partheniou@google.com>
- Loading branch information
1 parent
5932f32
commit 1de1655
Showing
8 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2022 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START batch_get_task] | ||
|
||
from google.cloud import batch_v1 | ||
|
||
|
||
def get_task(project_id: str, region: str, job_name: str, group_name: str, task_number: int) -> batch_v1.Task: | ||
""" | ||
Retrieve information about a Task. | ||
Args: | ||
project_id: project ID or project number of the Cloud project you want to use. | ||
region: name of the region hosts the job. | ||
job_name: the name of the job you want to retrieve information about. | ||
group_name: the name of the group that owns the task you want to check. Usually it's `group0`. | ||
task_number: number of the task you want to look up. | ||
Returns: | ||
A Task object representing the specified task. | ||
""" | ||
client = batch_v1.BatchServiceClient() | ||
|
||
return client.get_task(name=f"projects/{project_id}/locations/{region}/jobs/{job_name}" | ||
f"/taskGroups/{group_name}/tasks/{task_number}") | ||
# [END batch_get_task] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2022 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# [START batch_list_tasks] | ||
from typing import Iterable | ||
|
||
from google.cloud import batch_v1 | ||
|
||
|
||
def list_tasks(project_id: str, region: str, job_name: str, group_name: str) -> Iterable[batch_v1.Task]: | ||
""" | ||
Get a list of all jobs defined in given region. | ||
Args: | ||
project_id: project ID or project number of the Cloud project you want to use. | ||
region: name of the region hosting the jobs. | ||
job_name: name of the job which tasks you want to list. | ||
group_name: name of the group of tasks. Usually it's `group0`. | ||
Returns: | ||
An iterable collection of Task objects. | ||
""" | ||
client = batch_v1.BatchServiceClient() | ||
|
||
return client.list_tasks(parent=f"projects/{project_id}/locations/{region}/jobs/{job_name}/taskGroups/{group_name}") | ||
# [END batch_list_tasks] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters