-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the SDK to use
PATCH /deployments/{id}
endpoint for existing…
… deployments (#17050) Co-authored-by: Chris White <chris@prefect.io> Co-authored-by: nate nowack <thrast36@gmail.com>
- Loading branch information
1 parent
0794427
commit c8986ed
Showing
13 changed files
with
580 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
""" | ||
this integration test should | ||
- start serve w a schedule (no slug) | ||
- stop the serve process | ||
- start serve with no schedule | ||
- observe that deployment has no schedules | ||
- start serve with schedule (slug) | ||
- stop the serve process | ||
- start serve with no schedule | ||
- stop the serve process | ||
- observe that deployment still has that named schedule | ||
""" | ||
|
||
import signal | ||
from typing import Any | ||
|
||
from prefect import flow, get_client | ||
from prefect.client.schemas.objects import DeploymentSchedule | ||
from prefect.schedules import Cron | ||
|
||
DEPLOYMENT_NAME = "my-deployment" | ||
|
||
|
||
@flow | ||
def my_flow(): | ||
print("Hello, world!") | ||
|
||
|
||
def _handler(signum: int, frame: Any): | ||
raise KeyboardInterrupt("Simulating user interruption") | ||
|
||
|
||
def run_serve_with_schedule( | ||
timeout: int = 2, serve_kwargs: dict[str, Any] | None = None | ||
): | ||
signal.signal(signal.SIGALRM, _handler) | ||
signal.alarm(timeout) | ||
try: | ||
my_flow.serve(name=DEPLOYMENT_NAME, **(serve_kwargs or {})) | ||
except KeyboardInterrupt: | ||
print("Serve interrupted") | ||
finally: | ||
signal.alarm(0) | ||
|
||
|
||
def check_deployment_schedules(deployment_name: str) -> list[DeploymentSchedule]: | ||
with get_client(sync_client=True) as client: | ||
deployment = client.read_deployment_by_name(deployment_name) | ||
return deployment.schedules | ||
|
||
|
||
def main(): | ||
# case 1: Schedule without slug | ||
print("\nTest case 1: Schedule without slug") | ||
run_serve_with_schedule(serve_kwargs={"schedules": [Cron("0 9 * * *")]}) | ||
run_serve_with_schedule(serve_kwargs={"schedules": []}) | ||
schedules = check_deployment_schedules(f"my-flow/{DEPLOYMENT_NAME}") | ||
assert not schedules, ( | ||
f"Expected no schedules after removing unnamed schedule: {schedules}" | ||
) | ||
|
||
# case 2: Schedule with slug | ||
print("\nTest case 2: Schedule with slug") | ||
run_serve_with_schedule( | ||
serve_kwargs={"schedules": [Cron("0 9 * * *", slug="every-day-at-9am")]} | ||
) | ||
run_serve_with_schedule(serve_kwargs={"schedules": []}) | ||
schedules = check_deployment_schedules(f"my-flow/{DEPLOYMENT_NAME}") | ||
assert any(s.slug == "every-day-at-9am" for s in schedules), ( | ||
f"Expected named schedule to persist: {schedules}" | ||
) | ||
print("All tests passed!") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.