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

add prefect server services CLI commands #16706

Merged
merged 19 commits into from
Jan 14, 2025
Merged

add prefect server services CLI commands #16706

merged 19 commits into from
Jan 14, 2025

Conversation

zzstoatzz
Copy link
Collaborator

@zzstoatzz zzstoatzz commented Jan 13, 2025

wondering if maybe should be experimental as I think we may want to add some logging config and maybe update the signature of things - feedback?

  • start: start all loop services in the foreground
    • --background start them in the background
  • ls: list all known loop services and whether they are enabled
  • stop: stop any running loop services

both start and stop should be idempotent

in order to ensure the --background option can be managed by a single process, I created a hidden manager command under services (which does not show up in --help). open to other suggestions

demo usage
» prefect server services start

Starting services... Press CTRL+C to stop

23:16:55.600 | INFO    | prefect.cli.server - Started service: CancellationCleanup
23:16:55.601 | INFO    | prefect.cli.server - Started service: FlowRunNotifications
23:16:55.601 | INFO    | prefect.cli.server - Started service: Foreman
23:16:55.601 | INFO    | prefect.cli.server - Started service: MarkLateRuns
23:16:55.601 | INFO    | prefect.cli.server - Started service: FailExpiredPauses
23:16:55.601 | INFO    | prefect.cli.server - Started service: RecentDeploymentsScheduler
23:16:55.602 | INFO    | prefect.cli.server - Started service: Scheduler
23:16:55.602 | INFO    | prefect.cli.server - Started service: Telemetry
23:16:55.602 | INFO    | prefect.cli.server - Started service: ProactiveTriggers
^C23:16:56.784 | INFO    | prefect.cli.server - Received cancellation, stopping services...
23:16:56.784 | INFO    | prefect.cli.server - Stopped service: CancellationCleanup
23:16:56.784 | INFO    | prefect.cli.server - Stopped service: FlowRunNotifications
23:16:56.785 | INFO    | prefect.cli.server - Stopped service: Foreman
23:16:56.785 | INFO    | prefect.cli.server - Stopped service: MarkLateRuns
23:16:56.785 | INFO    | prefect.cli.server - Stopped service: FailExpiredPauses
23:16:56.785 | INFO    | prefect.cli.server - Stopped service: RecentDeploymentsScheduler
23:16:56.785 | INFO    | prefect.cli.server - Stopped service: Scheduler
23:16:56.785 | INFO    | prefect.cli.server - Stopped service: Telemetry
23:16:56.786 | INFO    | prefect.cli.server - Stopped service: ProactiveTriggers

All services stopped.
» prefect server services start --background
Starting service: CancellationCleanup
Starting service: FlowRunNotifications
Starting service: Foreman
Starting service: MarkLateRuns
Starting service: FailExpiredPauses
Starting service: RecentDeploymentsScheduler
Starting service: Scheduler
Starting service: Telemetry
Starting service: ProactiveTriggers

Services are running in the background.
Use `prefect server services stop` to stop them.
» prefect server services stop

Shutting down...
✓ Services stopped

All services stopped.
» prefect server services ls
                                                                  Available Services
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Name                         ┃ Enabled?  ┃ Description                                                                                             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ CancellationCleanup          │ True      │ A simple loop service responsible for cancelling tasks and subflows left over from                      │
│ FlowRunNotifications         │ True      │ A loop service that checks for flow run notifications that need to be sent.                             │
│ Foreman                      │ True      │ A loop service responsible for monitoring the status of workers.                                        │
│ MarkLateRuns                 │ True      │ A simple loop service responsible for identifying flow runs that are "late".                            │
│ FailExpiredPauses            │ True      │ A simple loop service responsible for identifying Paused flow runs that no longer can be resumed.       │
│ RecentDeploymentsScheduler   │ True      │ A scheduler that only schedules deployments that were updated very recently.                            │
│ Scheduler                    │ True      │ A loop service that schedules flow runs from deployments.                                               │
│ Telemetry                    │ True      │ This service sends anonymous data (e.g. count of flow runs) to Prefect to help us                       │
│ ProactiveTriggers            │ True      │ A loop service that runs the proactive triggers consumer                                                │
└──────────────────────────────┴───────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Copy link

codspeed-hq bot commented Jan 13, 2025

CodSpeed Performance Report

Merging #16706 will not alter performance

Comparing services-start (00c2373) with main (989321a)

Summary

✅ 2 untouched benchmarks

@zzstoatzz zzstoatzz force-pushed the services-start branch 2 times, most recently from 292f50b to 14ad097 Compare January 14, 2025 01:20
@github-actions github-actions bot added docs ui-replatform Related to the React UI rewrite labels Jan 14, 2025
@zzstoatzz zzstoatzz force-pushed the services-start branch 2 times, most recently from b71f4be to 37dff5c Compare January 14, 2025 01:52
@zzstoatzz zzstoatzz marked this pull request as ready for review January 14, 2025 03:20
@zzstoatzz zzstoatzz added cli Related to the Prefect CLI and removed docs ui-replatform Related to the React UI rewrite labels Jan 14, 2025
@zzstoatzz zzstoatzz force-pushed the services-start branch 3 times, most recently from de0efce to fbd11a0 Compare January 14, 2025 05:20
Copy link
Member

@cicdw cicdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few small comments, overall the implementation makes sense to me - I'll probably give it another pass in a bit

src/prefect/cli/server.py Show resolved Hide resolved
src/prefect/testing/cli.py Show resolved Hide resolved
),
):
"""Start all enabled Prefect services in one process."""
pid_file = Path(PREFECT_HOME.value()) / "services" / "manager.pid"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two minor points:

  • given this is an important file and a global, I suggest initializing it (but not creating it) at the top of the file and calling it PID_FILE
  • to mirror the server start command, I think it might be more consistent to use Path(PREFECT_HOME.value()) / "services.pid" rather than creating a new subdirectory

@zzstoatzz
Copy link
Collaborator Author

good calls @cicdw! suggestions applied in 0bbd572

Copy link
Member

@cicdw cicdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Propose to downgrade many of the new logs to DEBUG: I think anything that displays "implementation" information like service names is only useful when trying to understand what's going on under the hood, hence DEBUG vs. INFO which I think is broad strokes useful information relevant to all users ("services all started", etc.).

src/prefect/cli/server.py Outdated Show resolved Hide resolved
src/prefect/cli/server.py Outdated Show resolved Hide resolved
src/prefect/cli/server.py Outdated Show resolved Hide resolved
src/prefect/cli/server.py Outdated Show resolved Hide resolved
src/prefect/server/services/loop_service.py Outdated Show resolved Hide resolved
src/prefect/server/services/loop_service.py Outdated Show resolved Hide resolved
src/prefect/server/services/loop_service.py Outdated Show resolved Hide resolved
Copy link
Member

@cicdw cicdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zzstoatzz zzstoatzz merged commit 1fcaa30 into main Jan 14, 2025
44 of 45 checks passed
@zzstoatzz zzstoatzz deleted the services-start branch January 14, 2025 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the Prefect CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants