Skip to content

Commit

Permalink
Merge pull request #1744 from PrefectHQ/moar-labels
Browse files Browse the repository at this point in the history
Moar labels
  • Loading branch information
cicdw committed Nov 15, 2019
2 parents 0846e9a + 146f9b2 commit 59938d8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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

Expand All @@ -43,7 +44,7 @@ These changes are available in the [master branch](https://github.com/PrefectHQ/

### Contributors

- None
- [Brett Naul](https://github.com/bnaul)

## 0.7.1 <Badge text="beta" type="success"/>

Expand Down
2 changes: 1 addition & 1 deletion docs/cloud/agent/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
6 changes: 6 additions & 0 deletions src/prefect/core/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -1262,6 +1265,9 @@ def deploy(
self.environment.labels.add("local")
self.environment.labels.add(slugify(self.name))

if labels:
self.environment.labels.update(labels)

client = prefect.Client()
deployed_flow = client.deploy(
flow=self,
Expand Down

0 comments on commit 59938d8

Please sign in to comment.