From aa6747529e864d08ea0653311e55062388d37cad Mon Sep 17 00:00:00 2001 From: Chris White Date: Fri, 15 Nov 2019 12:15:52 -0800 Subject: [PATCH 1/4] Expose labels kwarg on flow.deploy for convenience labeling --- docs/cloud/agent/overview.md | 2 +- src/prefect/core/flow.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/cloud/agent/overview.md b/docs/cloud/agent/overview.md index 33f8eda3ffbd..982acf39dfa0 100644 --- a/docs/cloud/agent/overview.md +++ b/docs/cloud/agent/overview.md @@ -63,7 +63,7 @@ Prefect Agents rely on the use of a `RUNNER` token from Prefect Cloud. For infor ### Flow Affinity: Labels -Agents have an optional `labels` argument which allows for separation of execution when using multiple Agents. This is especially useful for teams who have various clusters running and they want different flows to run on specific clusters. For more information on labels and how to use them visit [Environments](../concepts/execution.html#labels). +Agents have an optional `labels` argument which allows for separation of execution when using multiple Agents. This is especially useful for teams who have various clusters running and they want different flows to run on specific clusters. For more information on labels and how to use them visit [Environments](../execution/overview.html#labels). By default Agents have no set labels and will therefore only pick up runs from flows which also have no specified Environment Labels. To set labels on your Agent they can be provided through a few methods: diff --git a/src/prefect/core/flow.py b/src/prefect/core/flow.py index 9bf91fb15eb6..7884704f8c6b 100644 --- a/src/prefect/core/flow.py +++ b/src/prefect/core/flow.py @@ -1231,6 +1231,7 @@ def deploy( self, project_name: str, build: bool = True, + labels: List[str] = None, set_schedule_active: bool = True, version_group_id: str = None, **kwargs: Any @@ -1243,6 +1244,8 @@ def deploy( - project_name (str): the project that should contain this flow. - build (bool, optional): if `True`, the flow's environment is built prior to serialization; defaults to `True` + - labels (List[str], optional): a list of labels to add to this Flow's environment; useful for + associating Flows with individual Agents - see http://docs.prefect.io/cloud/agent/overview.html#flow-affinity-labels - set_schedule_active (bool, optional): if `False`, will set the schedule to inactive in the database to prevent auto-scheduling runs (if the Flow has a schedule). Defaults to `True`. This can be changed later. @@ -1262,6 +1265,9 @@ def deploy( self.environment.labels.add("local") self.environment.labels.add(slugify(self.name)) + if labels: + self.environment.labels.add(labels) + client = prefect.Client() deployed_flow = client.deploy( flow=self, From 35298f666c269a911131f713a4414ab87e7ecba4 Mon Sep 17 00:00:00 2001 From: Chris White Date: Fri, 15 Nov 2019 12:17:15 -0800 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dc04956db7b..a9f5539c3082 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ These changes are available in the [master branch](https://github.com/PrefectHQ/ - Add graceful keyboard interrupt shutdown for all agents - [#1731](https://github.com/PrefectHQ/prefect/pull/1731) - `agent start` CLI command now allows for Agent kwargs - [#1737](https://github.com/PrefectHQ/prefect/pull/1737) - Add users to specify a custom Dockerfile for Docker storage - [#1738](https://github.com/PrefectHQ/prefect/pull/1738) +- Expose `labels` kwarg in `flow.deploy` for convenient labeling of Flows - [#1742](https://github.com/PrefectHQ/prefect/pull/1742) ### Task Library @@ -42,7 +43,7 @@ These changes are available in the [master branch](https://github.com/PrefectHQ/ ### Contributors -- None +- [Brett Naul](https://github.com/bnaul) ## 0.7.1 From 7311c5732c6d3ec22dacccddddb65afd931675b4 Mon Sep 17 00:00:00 2001 From: Chris White Date: Fri, 15 Nov 2019 12:18:54 -0800 Subject: [PATCH 3/4] Add -> update --- src/prefect/core/flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prefect/core/flow.py b/src/prefect/core/flow.py index 7884704f8c6b..a0120c53133b 100644 --- a/src/prefect/core/flow.py +++ b/src/prefect/core/flow.py @@ -1266,7 +1266,7 @@ def deploy( self.environment.labels.add(slugify(self.name)) if labels: - self.environment.labels.add(labels) + self.environment.labels.update(labels) client = prefect.Client() deployed_flow = client.deploy( From 146f9b23f4965134b6a8332724c271674792e406 Mon Sep 17 00:00:00 2001 From: Chris White Date: Fri, 15 Nov 2019 12:22:09 -0800 Subject: [PATCH 4/4] Hyphen to semicolor --- src/prefect/core/flow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prefect/core/flow.py b/src/prefect/core/flow.py index a0120c53133b..e961fa7cbb4c 100644 --- a/src/prefect/core/flow.py +++ b/src/prefect/core/flow.py @@ -1245,7 +1245,7 @@ def deploy( - build (bool, optional): if `True`, the flow's environment is built prior to serialization; defaults to `True` - labels (List[str], optional): a list of labels to add to this Flow's environment; useful for - associating Flows with individual Agents - see http://docs.prefect.io/cloud/agent/overview.html#flow-affinity-labels + associating Flows with individual Agents; see http://docs.prefect.io/cloud/agent/overview.html#flow-affinity-labels - set_schedule_active (bool, optional): if `False`, will set the schedule to inactive in the database to prevent auto-scheduling runs (if the Flow has a schedule). Defaults to `True`. This can be changed later.