Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Disable Deployments #15129

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
b604d1e
add disabled field to models
dylanbhughes Jul 12, 2024
13145b2
migrations for Deployment.disabled
dylanbhughes Jul 12, 2024
bfc17f1
remove typo
dylanbhughes Aug 19, 2024
1c90e83
first pass at porting disabled
dylanbhughes Aug 21, 2024
16d13c5
add disabled to actions schema
dylanbhughes Aug 28, 2024
53322b6
add disabled to deployment update server model
dylanbhughes Aug 28, 2024
7dfa565
move deployment disabled property next to paused like the rest of the…
dylanbhughes Aug 28, 2024
58b7a6f
add disabled to deployment response
dylanbhughes Aug 28, 2024
3eaf296
update migrations after rebase
dylanbhughes Aug 28, 2024
45f2ff9
pausing or resuming a deployment returns 409 if deployment is disabled
dylanbhughes Aug 28, 2024
d2a410c
create flow run from deployment returns 409 if deployment disabled
dylanbhughes Aug 28, 2024
80d5092
schedule deployment returns 409 if deployment is disabled
dylanbhughes Aug 28, 2024
738d7a7
disable and enable deployment endpoints
dylanbhughes Aug 28, 2024
d774b40
update docstring
dylanbhughes Aug 28, 2024
0d52da1
update docstrings
dylanbhughes Aug 28, 2024
6af0bbe
test to ensure scheduler respects disabled
dylanbhughes Aug 28, 2024
0796677
exclude disabled from client call just in caase
dylanbhughes Aug 29, 2024
c932976
test for deployment filter
dylanbhughes Aug 29, 2024
b6467a6
update enable/disable endpoints to match cloud
dylanbhughes Aug 29, 2024
d762a8a
add enable/disable deployment client methods
dylanbhughes Aug 29, 2024
d7ec08a
deployment disable/enable cli commands
dylanbhughes Aug 29, 2024
826d677
fix incorrectly updated deployment server tests
dylanbhughes Aug 29, 2024
c5e72b5
remove unused statement from postgres migration
dylanbhughes Aug 29, 2024
bdeac9c
correctly update the deployment_status type in postgres migration
dylanbhughes Aug 29, 2024
30268e5
enable disable toggles in the UI
dylanbhughes Aug 29, 2024
5fd3708
add tests for foreman
dylanbhughes Aug 29, 2024
a951802
emit events for disabling/enabling deployments
dylanbhughes Aug 29, 2024
7a0b4d6
deployment disabled run attempt event
dylanbhughes Aug 29, 2024
0b9c949
update docs routes
dylanbhughes Aug 29, 2024
1b405b1
test event emission for deployment api disable/enable events
dylanbhughes Aug 29, 2024
7f71ce4
Update ui/src/pages/Deployment.vue
dylanbhughes Sep 4, 2024
c3fb052
Update ui/src/pages/Deployments.vue
dylanbhughes Sep 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /api/deployments/{id}/disable
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /api/deployments/{id}/enable
---
158 changes: 157 additions & 1 deletion docs/3.0rc/api-ref/rest-api/server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3573,6 +3573,112 @@
}
}
},
"/api/deployments/{id}/disable": {
"post": {
"tags": [
"Deployments"
],
"summary": "Disable Deployment",
"description": "Set a deployment to disabled. Any auto-scheduled runs will be deleted and\nno new runs can be created until the deployment is enabled.",
"operationId": "disable_deployment_deployments__id__disable_post",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid",
"description": "The deployment id",
"title": "Id"
},
"description": "The deployment id"
},
{
"name": "x-prefect-api-version",
"in": "header",
"required": false,
"schema": {
"type": "string",
"title": "X-Prefect-Api-Version"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/deployments/{id}/enable": {
"post": {
"tags": [
"Deployments"
],
"summary": "Enable Deployment",
"description": "Set a deployment to enabled. Runs can be scheduled and created.",
"operationId": "enable_deployment_deployments__id__enable_post",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid",
"description": "The deployment id",
"title": "Id"
},
"description": "The deployment id"
},
{
"name": "x-prefect-api-version",
"in": "header",
"required": false,
"schema": {
"type": "string",
"title": "X-Prefect-Api-Version"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/api/saved_searches/": {
"put": {
"tags": [
Expand Down Expand Up @@ -15743,6 +15849,12 @@
"description": "Whether or not the deployment is paused.",
"default": false
},
"disabled": {
"type": "boolean",
"title": "Disabled",
"description": "Whether or not the deployment is disabled.",
"default": false
},
"schedules": {
"items": {
"$ref": "#/components/schemas/DeploymentScheduleCreate"
Expand Down Expand Up @@ -15979,6 +16091,17 @@
],
"description": "Filter criteria for `Deployment.paused`"
},
"disabled": {
"anyOf": [
{
"$ref": "#/components/schemas/DeploymentFilterDisabled"
},
{
"type": "null"
}
],
"description": "Filter criteria for `Deployment.disabled`"
},
"tags": {
"anyOf": [
{
Expand Down Expand Up @@ -16062,6 +16185,26 @@
"title": "DeploymentFilterConcurrencyLimit",
"description": "Filter by `Deployment.concurrency_limit`."
},
"DeploymentFilterDisabled": {
"properties": {
"eq_": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"title": "Eq ",
"description": "Only returns where deployment is/is not disabled"
}
},
"additionalProperties": false,
"type": "object",
"title": "DeploymentFilterDisabled",
"description": "Filter by `Deployment.disabled`."
},
"DeploymentFilterId": {
"properties": {
"any_": {
Expand Down Expand Up @@ -16484,6 +16627,12 @@
"description": "Whether or not the deployment is paused.",
"default": false
},
"disabled": {
"type": "boolean",
"title": "Disabled",
"description": "Whether or not the deployment is disabled.",
"default": false
},
"schedules": {
"items": {
"$ref": "#/components/schemas/DeploymentSchedule"
Expand Down Expand Up @@ -16947,7 +17096,8 @@
"type": "string",
"enum": [
"READY",
"NOT_READY"
"NOT_READY",
"DISABLED"
],
"title": "DeploymentStatus",
"description": "Enumeration of deployment statuses."
Expand Down Expand Up @@ -16982,6 +17132,12 @@
"description": "Whether or not the deployment is paused.",
"default": false
},
"disabled": {
"type": "boolean",
"title": "Disabled",
"description": "Whether or not the deployment is disabled.",
"default": false
},
"schedules": {
"items": {
"$ref": "#/components/schemas/DeploymentScheduleCreate"
Expand Down
4 changes: 3 additions & 1 deletion docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@
"3.0rc/api-ref/rest-api/server/deployments/read-deployment-schedules",
"3.0rc/api-ref/rest-api/server/deployments/create-deployment-schedules",
"3.0rc/api-ref/rest-api/server/deployments/delete-deployment-schedule",
"3.0rc/api-ref/rest-api/server/deployments/update-deployment-schedule"
"3.0rc/api-ref/rest-api/server/deployments/update-deployment-schedule",
"3.0rc/api-ref/rest-api/server/deployments/disable-deployment",
"3.0rc/api-ref/rest-api/server/deployments/enable-deployment"
]
},
{
Expand Down
44 changes: 44 additions & 0 deletions src/prefect/cli/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,50 @@ async def inspect(name: str):
app.console.print(Pretty(deployment_json))


@deployment_app.command()
async def disable(name: str):
"""
Disable a deployment.

\b
Example:
\b
$ prefect deployment disable "hello-world/my-deployment"
"""
assert_deployment_name_format(name)

async with get_client() as client:
try:
deployment = await client.read_deployment_by_name(name)
except ObjectNotFound:
exit_with_error(f"Deployment {name!r} not found!")

await client.disable_deployment(deployment.id)
exit_with_success(f"Disabled deployment {name!r}.")


@deployment_app.command()
async def enable(name: str):
"""
Enable a deployment.

\b
Example:
\b
$ prefect deployment enable "hello-world/my-deployment"
"""
assert_deployment_name_format(name)

async with get_client() as client:
try:
deployment = await client.read_deployment_by_name(name)
except ObjectNotFound:
exit_with_error(f"Deployment {name!r} not found!")

await client.enable_deployment(deployment.id)
exit_with_success(f"Enabled deployment {name!r}.")


@schedule_app.command("create")
async def create_schedule(
name: str,
Expand Down
35 changes: 35 additions & 0 deletions src/prefect/client/orchestration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,7 @@ async def create_deployment(
infrastructure_document_id: Optional[UUID] = None,
parameter_openapi_schema: Optional[Dict[str, Any]] = None,
paused: Optional[bool] = None,
disabled: Optional[bool] = None,
pull_steps: Optional[List[dict]] = None,
enforce_parameter_schema: Optional[bool] = None,
job_variables: Optional[Dict[str, Any]] = None,
Expand All @@ -1675,16 +1676,36 @@ async def create_deployment(
flow_id: the flow ID to create a deployment for
name: the name of the deployment
version: an optional version string for the deployment
schedules: an optional list of schedules for the deployment
concurrency_limit: an optional concurrency limit for flow runs
created by this deployment
parameters: an optional parameter schema for this deployment
parameter_openapi_schema: an optional OpenAPI schema for this deployment's parameters
description: an optional text description of this deployment
work_queue_name: the work queue associated with this deployment (optional)
work_pool_name: the work pool associated with this deployment (optional)
tags: an optional list of tags to apply to the deployment
storage_document_id: an reference to the storage block document
used for the deployed flow
path: The path to the working directory for the workflow, relative to remote storage or an absolute path
entrypoint: The path to the entrypoint for the workflow, relative to the `path`
infrastructure_document_id: an reference to the infrastructure block document
to use for this deployment
paused: an optional boolean. If True, flow runs will be scheduled as
described by this deployment's schedules
disabled: an optional boolean. If True, no flow runs will be created
for this deployment by any mechanism including automations and
API requests
pull_steps: an optional list of steps that describe how a worker should
prepare a flow run created from this deployment
enforce_parameter_schema: an optional boolean. If True, the API will
enforce the provided parameter schema when flow runs are created
job_variables: A dictionary of dot delimited infrastructure overrides that
will be applied at runtime; for example `env.CONFIG_KEY=config_value` or
`namespace='prefect'`. This argument was previously named `infra_overrides`.
Both arguments are supported for backwards compatibility.


Raises:
httpx.RequestError: if the deployment was not created for any reason

Expand All @@ -1709,6 +1730,7 @@ async def create_deployment(
job_variables=dict(job_variables or {}),
parameter_openapi_schema=parameter_openapi_schema,
paused=paused,
disabled=disabled,
schedules=schedules or [],
concurrency_limit=concurrency_limit,
pull_steps=pull_steps,
Expand All @@ -1728,6 +1750,9 @@ async def create_deployment(
if deployment_create.paused is None:
exclude.add("paused")

if deployment_create.disabled is None:
exclude.add("disabled")

if deployment_create.pull_steps is None:
exclude.add("pull_steps")

Expand All @@ -1750,6 +1775,16 @@ async def set_deployment_paused_state(self, deployment_id: UUID, paused: bool):
f"/deployments/{deployment_id}", json={"paused": paused}
)

async def disable_deployment(self, deployment_id: UUID):
await self._client.post(
f"/deployments/{deployment_id}/disable",
)

async def enable_deployment(self, deployment_id: UUID):
await self._client.post(
f"/deployments/{deployment_id}/enable",
)

async def update_deployment(
self,
deployment_id: UUID,
Expand Down
4 changes: 4 additions & 0 deletions src/prefect/client/schemas/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def convert_to_strings(cls, values):
name: str = Field(..., description="The name of the deployment.")
flow_id: UUID = Field(..., description="The ID of the flow to deploy.")
paused: Optional[bool] = Field(None)
disabled: Optional[bool] = Field(None)
schedules: List[DeploymentScheduleCreate] = Field(
default_factory=list,
description="A list of schedules for the deployment.",
Expand Down Expand Up @@ -229,6 +230,9 @@ def remove_old_fields(cls, values):
paused: Optional[bool] = Field(
default=None, description="Whether or not the deployment is paused."
)
disabled: Optional[bool] = Field(
default=None, description="Whether or not the deployment is disabled."
)
schedules: Optional[List[DeploymentScheduleCreate]] = Field(
default=None,
description="A list of schedules for the deployment.",
Expand Down
5 changes: 5 additions & 0 deletions src/prefect/client/schemas/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class DeploymentStatus(AutoEnum):

READY = AutoEnum.auto()
NOT_READY = AutoEnum.auto()
DISABLED = AutoEnum.auto()


class WorkQueueStatus(AutoEnum):
Expand Down Expand Up @@ -1113,6 +1114,10 @@ class Deployment(ObjectBaseModel):
"Whether or not the deployment should enforce the parameter schema."
),
)
disabled: bool = Field(
default=False,
description="If true, no flow runs will be created for the deployment.",
)


class ConcurrencyLimit(ObjectBaseModel):
Expand Down
Loading