Skip to content

Commit 7b1ae60

Browse files
authored
enh: rename pipeline UI (#187)
1 parent 20e6665 commit 7b1ae60

File tree

6 files changed

+42
-1
lines changed

6 files changed

+42
-1
lines changed

deployer/cli.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ def deploy( # noqa: C901
227227
"Defaults to '{pipeline_name}-experiment'.",
228228
),
229229
] = None,
230+
run_name: Annotated[
231+
Optional[str],
232+
typer.Option(
233+
"--run-name",
234+
"-rn",
235+
help="The pipeline's run name. Displayed in the UI."
236+
"Defaults to '{pipeline_name}-{tags}-%Y%m%d%H%M%S'.",
237+
),
238+
] = None,
230239
skip_validation: Annotated[
231240
bool,
232241
typer.Option(
@@ -276,6 +285,7 @@ def deploy( # noqa: C901
276285
staging_bucket_name=vertex_settings.VERTEX_STAGING_BUCKET_NAME,
277286
service_account=vertex_settings.VERTEX_SERVICE_ACCOUNT,
278287
pipeline_name=pipeline_name,
288+
run_name=run_name,
279289
pipeline_func=pipeline_func,
280290
gar_location=vertex_settings.GAR_LOCATION,
281291
gar_repo_id=vertex_settings.GAR_PIPELINES_REPO_ID,

deployer/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from pathlib import Path
23

34
TEMPLATES_PATH = Path(__file__).parent / "_templates"
@@ -64,3 +65,5 @@
6465
"you can add the following flags to the deploy command if not set in your config:\n"
6566
"--schedule --cron=cron_expression --scheduler-timezone=IANA_time_zone\n"
6667
)
68+
69+
VALID_RUN_NAME_PATTERN = re.compile("^[a-z][-a-z0-9]{0,127}$", re.IGNORECASE)

deployer/pipeline_deployer.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import os
4+
from datetime import datetime
45
from pathlib import Path
56
from typing import Callable, List, Optional
67

@@ -11,6 +12,7 @@
1112
from loguru import logger
1213
from requests import HTTPError
1314

15+
from deployer import constants
1416
from deployer.utils.exceptions import (
1517
MissingGoogleArtifactRegistryHostError,
1618
TagNotFoundError,
@@ -24,6 +26,7 @@ def __init__(
2426
self,
2527
pipeline_name: str,
2628
pipeline_func: Callable,
29+
run_name: Optional[str] = None,
2730
project_id: Optional[str] = None,
2831
region: Optional[str] = None,
2932
staging_bucket_name: Optional[str] = None,
@@ -39,6 +42,7 @@ def __init__(
3942
self.service_account = service_account
4043

4144
self.pipeline_name = pipeline_name
45+
self.run_name = run_name
4246
self.pipeline_func = pipeline_func
4347

4448
self.gar_location = gar_location
@@ -106,6 +110,26 @@ def _check_experiment_name(self, experiment_name: Optional[str] = None) -> str:
106110

107111
return experiment_name
108112

113+
def _check_run_name(self, tag: Optional[str] = None) -> None:
114+
"""Each run name (job_id) must be unique.
115+
We thus always add a timestamp to ensure uniqueness.
116+
"""
117+
now_str = datetime.now().strftime("%Y%m%d-%H%M%S")
118+
if self.run_name is None:
119+
self.run_name = f"{self.pipeline_name}"
120+
if tag:
121+
self.run_name += f"-{tag}"
122+
123+
self.run_name = self.run_name.replace("_", "-")
124+
self.run_name += f"-{now_str}"
125+
126+
if not constants.VALID_RUN_NAME_PATTERN.match(self.run_name):
127+
raise ValueError(
128+
f"Run name {self.run_name} does not match the pattern"
129+
f" {constants.VALID_RUN_NAME_PATTERN.pattern}"
130+
)
131+
logger.debug(f"run_name is: {self.run_name}")
132+
109133
def _create_pipeline_job(
110134
self,
111135
template_path: str,
@@ -139,6 +163,7 @@ def _create_pipeline_job(
139163
""" # noqa: E501
140164
job = aiplatform.PipelineJob(
141165
display_name=self.pipeline_name,
166+
job_id=self.run_name,
142167
template_path=template_path,
143168
pipeline_root=self.staging_bucket_uri,
144169
location=self.region,
@@ -210,7 +235,7 @@ def run(
210235
tag (str, optional): Tag of the pipeline template. Defaults to None.
211236
""" # noqa: E501
212237
experiment_name = self._check_experiment_name(experiment_name)
213-
238+
self._check_run_name(tag=tag)
214239
template_path = self._get_template_path(tag)
215240

216241
logger.debug(

deployer/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class _DeployerDeploySettings(CustomBaseModel):
3030
config_name: Optional[str] = None
3131
enable_caching: Optional[bool] = None
3232
experiment_name: Optional[str] = None
33+
run_name: Optional[str] = None
3334
skip_validation: bool = True
3435

3536

docs/CLI_REFERENCE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ $ vertex-deployer deploy [OPTIONS] PIPELINE_NAMES...
123123
* `-cn, --config-name TEXT`: Name of the json/py file with parameter values and input artifacts to use when running the pipeline. It must be in the pipeline config dir. e.g. `config_dev.json` for `./vertex/configs/{pipeline-name}/config_dev.json`.
124124
* `-ec, --enable-caching / -nec, --no-cache`: Whether to turn on caching for the run.If this is not set, defaults to the compile time settings, which are True for alltasks by default, while users may specify different caching options for individualtasks. If this is set, the setting applies to all tasks in the pipeline.Overrides the compile time settings. Defaults to None.
125125
* `-en, --experiment-name TEXT`: The name of the experiment to run the pipeline in.Defaults to '{pipeline_name}-experiment'.
126+
* `-rn, --run-name TEXT`: The pipeline's run name. Displayed in the UI.Defaults to '{pipeline_name}-{tags}-%Y%m%d%H%M%S'.
126127
* `-y, --skip-validation / -n, --no-skip`: Whether to continue without user validation of the settings. [default: skip-validation]
127128
* `--help`: Show this message and exit.
128129

tests/integration_tests/test_init.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def test_init_command_with_user_input(tmp_path):
6060
"",
6161
"",
6262
"",
63+
"",
6364
"y",
6465
"json",
6566
"",

0 commit comments

Comments
 (0)