|
15 | 15 | # limitations under the License.
|
16 | 16 | #
|
17 | 17 |
|
18 |
| -from typing import Optional |
| 18 | +from typing import List, Optional |
19 | 19 |
|
20 | 20 | from google.auth import credentials as auth_credentials
|
21 | 21 | from google.cloud.aiplatform import base
|
|
39 | 39 | from google.cloud.aiplatform_v1beta1.types import (
|
40 | 40 | pipeline_job as gca_pipeline_job_v1beta1,
|
41 | 41 | )
|
| 42 | +from google.protobuf import field_mask_pb2 as field_mask |
42 | 43 |
|
43 | 44 |
|
44 | 45 | _LOGGER = base.Logger(__name__)
|
@@ -68,6 +69,7 @@ def __init__(
|
68 | 69 | ):
|
69 | 70 | """Retrieves a PipelineJobSchedule resource and instantiates its
|
70 | 71 | representation.
|
| 72 | +
|
71 | 73 | Args:
|
72 | 74 | pipeline_job (PipelineJob):
|
73 | 75 | Required. PipelineJob used to init the schedule.
|
@@ -255,3 +257,131 @@ def _create(
|
255 | 257 | )
|
256 | 258 |
|
257 | 259 | _LOGGER.info("View Schedule:\n%s" % self._dashboard_uri())
|
| 260 | + |
| 261 | + @classmethod |
| 262 | + def list( |
| 263 | + cls, |
| 264 | + filter: Optional[str] = None, |
| 265 | + order_by: Optional[str] = None, |
| 266 | + enable_simple_view: bool = True, |
| 267 | + project: Optional[str] = None, |
| 268 | + location: Optional[str] = None, |
| 269 | + credentials: Optional[auth_credentials.Credentials] = None, |
| 270 | + ) -> List["PipelineJobSchedule"]: |
| 271 | + """List all instances of this PipelineJobSchedule resource. |
| 272 | +
|
| 273 | + Example Usage: |
| 274 | +
|
| 275 | + aiplatform.PipelineJobSchedule.list( |
| 276 | + filter='display_name="experiment_a27"', |
| 277 | + order_by='create_time desc' |
| 278 | + ) |
| 279 | +
|
| 280 | + Args: |
| 281 | + filter (str): |
| 282 | + Optional. An expression for filtering the results of the request. |
| 283 | + For field names both snake_case and camelCase are supported. |
| 284 | + order_by (str): |
| 285 | + Optional. A comma-separated list of fields to order by, sorted in |
| 286 | + ascending order. Use "desc" after a field name for descending. |
| 287 | + Supported fields: `display_name`, `create_time`, `update_time` |
| 288 | + enable_simple_view (bool): |
| 289 | + Optional. Whether to pass the `read_mask` parameter to the list call. |
| 290 | + Defaults to False if not provided. This will improve the performance of calling |
| 291 | + list(). However, the returned PipelineJobSchedule list will not include all fields for |
| 292 | + each PipelineJobSchedule. Setting this to True will exclude the following fields in your |
| 293 | + response: 'create_pipeline_job_request', 'next_run_time', 'last_pause_time', |
| 294 | + 'last_resume_time', 'max_concurrent_run_count', 'allow_queueing','last_scheduled_run_response'. |
| 295 | + The following fields will be included in each PipelineJobSchedule resource in your |
| 296 | + response: 'name', 'display_name', 'start_time', 'end_time', 'max_run_count', |
| 297 | + 'started_run_count', 'state', 'create_time', 'update_time', 'cron', 'catch_up'. |
| 298 | + project (str): |
| 299 | + Optional. Project to retrieve list from. If not set, project |
| 300 | + set in aiplatform.init will be used. |
| 301 | + location (str): |
| 302 | + Optional. Location to retrieve list from. If not set, location |
| 303 | + set in aiplatform.init will be used. |
| 304 | + credentials (auth_credentials.Credentials): |
| 305 | + Optional. Custom credentials to use to retrieve list. Overrides |
| 306 | + credentials set in aiplatform.init. |
| 307 | +
|
| 308 | + Returns: |
| 309 | + List[PipelineJobSchedule] - A list of PipelineJobSchedule resource objects. |
| 310 | + """ |
| 311 | + |
| 312 | + read_mask_fields = None |
| 313 | + |
| 314 | + if enable_simple_view: |
| 315 | + read_mask_fields = field_mask.FieldMask(paths=_READ_MASK_FIELDS) |
| 316 | + _LOGGER.warn( |
| 317 | + "By enabling simple view, the PipelineJobSchedule resources returned from this method will not contain all fields." |
| 318 | + ) |
| 319 | + |
| 320 | + return cls._list_with_local_order( |
| 321 | + filter=filter, |
| 322 | + order_by=order_by, |
| 323 | + read_mask=read_mask_fields, |
| 324 | + project=project, |
| 325 | + location=location, |
| 326 | + credentials=credentials, |
| 327 | + ) |
| 328 | + |
| 329 | + def list_jobs( |
| 330 | + self, |
| 331 | + filter: Optional[str] = None, |
| 332 | + order_by: Optional[str] = None, |
| 333 | + enable_simple_view: bool = False, |
| 334 | + project: Optional[str] = None, |
| 335 | + location: Optional[str] = None, |
| 336 | + credentials: Optional[auth_credentials.Credentials] = None, |
| 337 | + ) -> List[PipelineJob]: |
| 338 | + """List all PipelineJob 's created by this PipelineJobSchedule. |
| 339 | +
|
| 340 | + Example usage: |
| 341 | +
|
| 342 | + pipeline_job_schedule.list_jobs(order_by='create_time_desc') |
| 343 | +
|
| 344 | + Args: |
| 345 | + filter (str): |
| 346 | + Optional. An expression for filtering the results of the request. |
| 347 | + For field names both snake_case and camelCase are supported. |
| 348 | + order_by (str): |
| 349 | + Optional. A comma-separated list of fields to order by, sorted in |
| 350 | + ascending order. Use "desc" after a field name for descending. |
| 351 | + Supported fields: `display_name`, `create_time`, `update_time` |
| 352 | + enable_simple_view (bool): |
| 353 | + Optional. Whether to pass the `read_mask` parameter to the list call. |
| 354 | + Defaults to False if not provided. This will improve the performance of calling |
| 355 | + list(). However, the returned PipelineJob list will not include all fields for |
| 356 | + each PipelineJob. Setting this to True will exclude the following fields in your |
| 357 | + response: `runtime_config`, `service_account`, `network`, and some subfields of |
| 358 | + `pipeline_spec` and `job_detail`. The following fields will be included in |
| 359 | + each PipelineJob resource in your response: `state`, `display_name`, |
| 360 | + `pipeline_spec.pipeline_info`, `create_time`, `start_time`, `end_time`, |
| 361 | + `update_time`, `labels`, `template_uri`, `template_metadata.version`, |
| 362 | + `job_detail.pipeline_run_context`, `job_detail.pipeline_context`. |
| 363 | + project (str): |
| 364 | + Optional. Project to retrieve list from. If not set, project |
| 365 | + set in aiplatform.init will be used. |
| 366 | + location (str): |
| 367 | + Optional. Location to retrieve list from. If not set, location |
| 368 | + set in aiplatform.init will be used. |
| 369 | + credentials (auth_credentials.Credentials): |
| 370 | + Optional. Custom credentials to use to retrieve list. Overrides |
| 371 | + credentials set in aiplatform.init. |
| 372 | +
|
| 373 | + Returns: |
| 374 | + List[PipelineJob] - A list of PipelineJob resource objects. |
| 375 | + """ |
| 376 | + list_filter = f"schedule_name={self._gca_resource.name}" |
| 377 | + if filter: |
| 378 | + list_filter = list_filter + f" AND {filter}" |
| 379 | + |
| 380 | + return PipelineJob.list( |
| 381 | + filter=list_filter, |
| 382 | + order_by=order_by, |
| 383 | + enable_simple_view=enable_simple_view, |
| 384 | + project=project, |
| 385 | + location=location, |
| 386 | + credentials=credentials, |
| 387 | + ) |
0 commit comments