Log PermissionError when UI static directory creation fails
When running in HA with a read-only site-packages directory, the
OrchestrationClient would fail silently when trying to create the UI
static directory. The PermissionError was propagated up and eventually
sent to the dead letter queue without any clear error message.
This change catches PermissionError in create_ui_app() and logs a clear
error message with the path and resolution (setting
PREFECT_UI_STATIC_DIRECTORY to a writable location).
Add bounded queue for QueueService to prevent OOM during server outages
When the Prefect API server is unreachable for extended periods, the
in-memory event queue in EventsWorker grows without bound, eventually
causing OOM kills in long-running worker processes.
This change adds:
1. A `_max_queue_size` class variable on `_QueueServiceBase` (default 0,
meaning unbounded) that subclasses can override to set a queue bound.
2. A `try/except queue.Full` in `QueueService.send()` that drops items
with a warning log instead of blocking or crashing.
3. A new `PREFECT_EVENTS_WORKER_QUEUE_MAX_SIZE` setting (default 10000)
in a new `EventsSettings` model, which `EventsWorker` reads to
configure its queue bound.
4. The `reset_for_fork()` method preserves the maxsize when recreating
the queue in child processes.
The change is fully backward-compatible: existing QueueService subclasses
keep `_max_queue_size=0` (unbounded), and users can set the env var to 0
to restore the previous unbounded behavior.
Closes #21031
Add bounded queue support to QueueService to prevent OOM
Adds a `_max_queue_size` class variable to `_QueueServiceBase` (default 0
= unbounded, preserving current behavior). When set, the internal
`queue.Queue` is created with that `maxsize`. If the queue is full,
`QueueService.send()` drops the item with a warning instead of blocking.
Adds a `PREFECT_CLIENT_EVENTS_QUEUE_MAX_SIZE` setting that `EventsWorker`
reads to configure its queue bound. This prevents unbounded memory growth
when the Prefect server is temporarily unreachable during long-running
flows.
Closes #21031
Add PREFECT_CLIENT_EMIT_EVENTS setting to disable client-side event emission
Adds a new `client.emit_events` boolean setting (env var
`PREFECT_CLIENT_EMIT_EVENTS`) that controls whether the client emits
events to the Prefect server. Defaults to `True` (no behavior change).
When set to `False`, `should_emit_events()` short-circuits and returns
`False` before checking API URL/key configuration, preventing any events
from being created or queued.
This is useful for long-running flows that don't rely on event-driven
features (automations, triggers) and want to reduce memory usage from
the EventsWorker queue.
Closes #21030