-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
refactor(events): use pydantic schemas for events #5748
Merged
Merged
Conversation
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
psychedelicious
requested review from
blessedcoolant,
maryhipp,
hipsterusername and
brandonrising
as code owners
February 19, 2024 10:54
github-actions
bot
added
api
python
PRs that change python files
services
PRs that change app services
frontend
PRs that change frontend files
labels
Feb 19, 2024
psychedelicious
force-pushed
the
refactor/nodes/merge-processors
branch
from
February 19, 2024 22:52
41818ea
to
891c56f
Compare
psychedelicious
force-pushed
the
psyche/refactor/events
branch
3 times, most recently
from
February 21, 2024 09:36
dd8c4a4
to
c496cc0
Compare
psychedelicious
force-pushed
the
psyche/refactor/events
branch
from
March 10, 2024 08:04
c496cc0
to
05f60d5
Compare
psychedelicious
force-pushed
the
psyche/refactor/events
branch
from
March 10, 2024 08:55
05f60d5
to
4f123b0
Compare
github-actions
bot
added
documentation
Improvements or additions to documentation
invocations
PRs that change invocations
backend
PRs that change backend files
installer
PRs that change the installer
CICD
FrontendDeps
labels
Mar 10, 2024
psychedelicious
force-pushed
the
psyche/refactor/events
branch
from
March 10, 2024 11:45
4f123b0
to
4a6964f
Compare
We don't need to use the payload schema registry. All our events are dispatched as pydantic models, which are already validated on instantiation. We do want to add all events to the OpenAPI schema, and we referred to the payload schema registry for this. To get all events, add a simple helper to EventBase. This is functionally identical to using the schema registry.
- Restore calculation of step percentage but in the backend instead of client - Simplify signatures for denoise progress event callbacks - Clean up `step_callback.py` (types, do not recreate constant matrix on every step, formatting)
Deterministic ordering prevents extraneous, non-functional changes to the autogenerated types
Some subtle changes happened between this PR's last update and now. Bring them into the file.
Just a bit clearer without needing `isinstance` checks.
This lets the event sets be consumed programmatically.
There's no longer any need for session-scoped events now that we have the session queue. Session started/completed/canceled map 1-to-1 to queue item status events, but queue item status events also have an event for failed state. We can simplify queue and processor handling substantially by removing session events and instead using queue item events. - Remove the session-scoped events entirely. - Remove all event handling from session queue. The processor still needs to respond to some events from the queue: `QueueClearedEvent`, `BatchEnqueuedEvent` and `QueueItemStatusChangedEvent`. - Pass an `is_canceled` callback to the invocation context instead of the cancel event - Update processor logic to ensure the local instance of the current queue item is synced with the instance in the database. This prevents race conditions and ensures lifecycle callback do not get stale callbacks. - Update docstrings and comments - Add `complete_queue_item` method to session queue service as an explicit way to mark a queue item as successfully completed. Previously, the queue listened for session complete events to do this. Closes #6442
- Add a simple helper to create socket actions in a less error-prone way - Organize and tidy sio files
psychedelicious
force-pushed
the
psyche/refactor/events
branch
from
May 26, 2024 22:57
cc130b5
to
9e99cc8
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
api
backend
PRs that change backend files
CICD
documentation
Improvements or additions to documentation
frontend
PRs that change frontend files
FrontendDeps
installer
PRs that change the installer
invocations
PRs that change invocations
python
PRs that change python files
python-deps
PRs that change python dependencies
python-tests
PRs that change python tests
PythonDeps
PythonTests
Root
services
PRs that change app services
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this? (check all applicable)
Have you discussed this change with the InvokeAI team?
Description
refactor(events): use pydantic schemas for events
Our events handling and implementation has a couple pain points:
fastapi-events
has a neat feature where you can create a pydantic model as an event payload, give it an__event_name__
attr, and then dispatch the model directly.This allows us to eliminate a layer of indirection and some unpleasant complexity:
isinstance
on them if needed.build
class method, encapsulating this logic. The build methods are provided as few args as possible. For example,InvocationStartedEvent.build()
gets the invocation instance and queue item, and can choose the data it wants to include in the event payload.fastapi-events
to collect all payload models into one place, making it trivial to keep our schema and frontend types in sync.Note: Over half the lines in this PR are from the new autogenerated types. This PR is otherwise a net reduction in LOC.
Related Tickets & Documents
QA Instructions, Screenshots, Recordings
Give the app a spin. Things that use events:
Merge Plan
This PR can be merged when approved
Added/updated tests?