Warning
This document is for an in-development version of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.
Server-Sent Events: event types, routing and producers
With enable_sse_updates on, Galaxy pushes change notifications to browsers over a single
Server-Sent Events stream. This page describes the events for client and Galaxy
developers: what each event carries, who receives it, and how the server produces it. Deployment,
configuration, monitoring and proxy setup are covered in the admin guide,
Server-Sent Events (SSE) for real-time updates.
The stream
A client opens one EventSource against GET /api/events/stream and receives every event type
on it. The first frame on every connection is a ready event, sent once the server has registered
the connection; every event dispatched after that reaches it. A keepalive comment follows every 30
seconds of silence.
The endpoint accepts connections even when enable_sse_updates is off, but then no producer sends
change events. Clients therefore choose between the stream and polling by the enable_sse_updates
value in /api/configuration, not by whether the connection opens.
Events are wake-up signals: they carry ids and states, and the client refetches the full objects
through the regular, access-controlled API. A client should also refetch after reconnecting, since
events sent while it was disconnected are lost (only notification_status is replayed, see below).
Event types
Event |
Data |
Sent when |
|---|---|---|
|
|
A history, or a dataset or collection in it, changed. |
|
|
One of the user’s interactive tool entry points was configured. Refetch |
|
|
A workflow invocation’s state changed, one of its steps was added or changed state, or a message was added to it. |
|
|
A job’s state changed. |
|
A |
A notification was sent to the user. |
|
A |
A broadcast was created. |
|
A |
On reconnect with |
All ids are encoded. An invocation_update for an invocation whose state is unchanged means its
steps or messages changed. A job_update with {"resync": true} replaces the individual entries
when one transaction changed more than 500 jobs of the recipient (for example a tool mapped over a
large collection): the client refetches all jobs it shows.
Routing
Events are routed to the users and anonymous browser sessions allowed to see them:
history_updategoes to the owner of the history, or for an anonymous history to its browser session.invocation_updategoes to the owner of the invocation’s history.job_updategoes to the job’s user. An anonymous job’s events go to the owner of its history once a user has logged in and taken over that history, and otherwise to its browser session.entry_point_updateandnotification_updatego to their user,broadcast_updateto everyone.
In addition, history_update, invocation_update and job_update reach the viewers of a
history: users or sessions watching a history they don’t own, such as a published history or one
shared with them. A client subscribes and unsubscribes with:
POST /api/events/history-subscriptions {"history_ids": [<id>, ...]}
DELETE /api/events/history-subscriptions {"history_ids": [<id>, ...]}
Both return 204. Only histories the requester can access are subscribed (owned, shared with them, importable or published, or their anonymous current history); other and malformed ids are skipped. Access is checked when subscribing: a viewer keeps receiving events for a history made private later until it unsubscribes or disconnects. Every web worker holds the subscriptions of the users and sessions connected to it, and drops them when the last connection of that user or session on the worker closes, so clients re-send them after reconnecting. A viewer receives only the entries for the histories it watches, and an owner subscribed to their own history receives each event once.
Producers
Every event travels as a Kombu control task to all web workers (galaxy.queue_worker), and each
worker pushes it to the connections it holds. SSEEventDispatcher (galaxy.managers.sse_dispatch)
sends these tasks from any Galaxy process with an AMQP connection.
history_updatecomes fromHistoryAuditMonitor, which follows thehistory_audittable that database triggers fill (PostgreSQLLISTEN/NOTIFY, or polling on SQLite).invocation_updateandjob_updatecome fromChangeEventPublisher(galaxy.managers.change_events). It listens on the app’s SQLAlchemy sessionmaker, collects the invocations and jobs changed in a transaction (galaxy.model.pending_changes) and sends them when the root transaction commits, in whichever process committed it. Rolled back transactions and savepoints send nothing.entry_point_updateand the notification events are sent explicitly by the code that makes the change.
ChangeEventPublisher sees changes made through the ORM unit of work: state assignments on
invocations and jobs, new invocation steps and messages, and the JobStateHistory row that
Job.set_state adds. A bulk UPDATE that changes invocation or job states bypasses the unit of
work and must record its changes itself with record_invocation_change or record_job_change, as
WorkflowInvocation.set_state and WorkflowInvocation.cancel_invocation_steps do. Otherwise it
sends no event.
Tests
galaxy_test.base.sse provides SSELineListener, a stream client for integration tests, and
SSEWaiter, which backs the populators’ waits (wait_for_job, wait_for_history,
wait_for_invocation, …). Against a server with enable_sse_updates, these waits re-check only
when a matching event arrives, so a missing event makes them time out; for a history the current
user doesn’t own, they subscribe as a viewer for the wait. Against other servers they poll.
SSEIntegrationTestCase in galaxy_test.driver.integration_util starts a server with SSE updates
enabled.