Commit Graph

1577 Commits

Author SHA1 Message Date
psychedelicious
fff5d12648 tidy(bulk_download): don't store events service separately
Using the invoker object directly leaves no ambiguity as to what `_events_bus` actually is.
2024-02-29 13:28:21 -05:00
psychedelicious
dabb5e2cf4 tidy(bulk_download): do not rely on pagination API to get all images for board
We can get all images for the board as a list of image names, then pass that to `_image_handler` to get the DTOs, decoupling from the pagination API.
2024-02-29 13:28:21 -05:00
psychedelicious
8927620c2d tidy(bulk_download): nit - use or as a coalescing operator
Just a bit cleaner.
2024-02-29 13:28:21 -05:00
psychedelicious
8244733145 tidy(bulk_download): use single underscore for private attrs
Double underscores are used in the app but it doesn't actually do or convey anything that single underscores don't already do. Considered unpythonic except for actual dunder/magic methods.
2024-02-29 13:28:21 -05:00
psychedelicious
ac25ad0b67 tidy(bulk_download): remove class-level attr annotations
These can be misleading as they shadow actual assigned class attributes. This pattern is in the rest of the app but it shouldn't be.
2024-02-29 13:28:21 -05:00
psychedelicious
8abb57eedb tidy(bulk_download): remove extraneous abstract methods
`start`, `stop` and `__init__` are not required in implementations of an ABC or service.
2024-02-29 13:28:21 -05:00
psychedelicious
b7f152b45a tidy(bulk_download): clean up comments 2024-02-29 13:28:21 -05:00
Stefan Tobler
28ae16001e adding bulk_download_item_name to socket events 2024-02-29 13:28:21 -05:00
Stefan Tobler
6468b044d8 refactoring handlers to do null check 2024-02-29 13:28:21 -05:00
Stefan Tobler
ec129662a6 removing dependency on an output folder, embrace python temp folder for bulk download 2024-02-29 13:28:21 -05:00
Stefan Tobler
ba28709f2d moving the responsibility of cleaning up board names to the service not the route 2024-02-29 13:28:21 -05:00
Stefan Tobler
bb40196a17 using temp directory for downloads 2024-02-29 13:28:21 -05:00
Stefan Tobler
b1301e1cbc returning the bulk_download_item_name on response for possible polling 2024-02-29 13:28:21 -05:00
Stefan Tobler
67df224df4 narrowing bulk_download stop service scope 2024-02-29 13:28:21 -05:00
Stefan Tobler
4dfa1e3d03 cleaning up bulk download zip after the response is complete 2024-02-29 13:28:21 -05:00
Stefan Tobler
37e80f62b3 refactoring bulk_download to be better managed 2024-02-29 13:28:21 -05:00
Stefan Tobler
c2b12f8849 refactoring bulkdownload to consider image category 2024-02-29 13:28:21 -05:00
Stefan Tobler
1e00b9760a fixing issue where default board did not return images 2024-02-29 13:28:21 -05:00
Stefan Tobler
c4cdaaf4dd using the board name to download boards 2024-02-29 13:28:21 -05:00
Stefan Tobler
9c61a40659 reworking some of the logic to use a default room, adding endpoint to download file on complete 2024-02-29 13:28:21 -05:00
Stefan Tobler
cacd0b9c4e linted and styling 2024-02-29 13:28:21 -05:00
Stefan Tobler
2dd67c3b71 implementation of bulkdownload background task 2024-02-29 13:28:21 -05:00
Stefan Tobler
cf6eb1394a adding socket events for bulk download 2024-02-29 13:28:21 -05:00
Stefan Tobler
aba9cd3f9a groundwork for the bulk_download_service 2024-02-29 13:28:21 -05:00
psychedelicious
03db2cba6c chore(nodes): update TODO comment 2024-02-29 13:28:20 -05:00
psychedelicious
9ea8c2af54 tidy(nodes): clean up profiler/stats in processor, better comments 2024-02-29 13:28:20 -05:00
psychedelicious
37b8d59347 fix(nodes): fix typing on stats service context manager 2024-02-29 13:28:20 -05:00
psychedelicious
18e1fe83d5 fix(nodes): fix model load events
was accessing incorrect properties in event data
2024-02-29 13:28:20 -05:00
psychedelicious
198ed222c4 feat(nodes): making invocation class var in processor 2024-02-29 13:28:20 -05:00
psychedelicious
62199b0fb1 feat(nodes): improved error messages in processor 2024-02-29 13:28:20 -05:00
psychedelicious
bdb843a6fb feat(nodes): make processor thread limit and polling interval configurable 2024-02-29 13:28:20 -05:00
psychedelicious
d37840712b chore(nodes): better comments for invocation context 2024-02-29 13:28:20 -05:00
psychedelicious
5c4779907f chore(nodes): "context_data" -> "data"
Changed within InvocationContext, for brevity.
2024-02-29 13:28:20 -05:00
psychedelicious
8870e0f8f2 refactor(nodes): move is_canceled to context.util 2024-02-29 13:28:20 -05:00
psychedelicious
d35f986351 feat(nodes): add whole queue_item to InvocationContextData
No reason to not have the whole thing in there.
2024-02-29 13:28:20 -05:00
psychedelicious
fafaa09f5e tidy(nodes): remove extraneous comments 2024-02-29 13:28:20 -05:00
psychedelicious
03c5de78e1 feat(nodes): better invocation error messages 2024-02-29 13:28:20 -05:00
psychedelicious
e85634742e chore(nodes): add comments for cancel state 2024-02-29 13:28:20 -05:00
psychedelicious
b4a120af42 feat(nodes): promote is_canceled to public node API 2024-02-29 13:28:20 -05:00
psychedelicious
276a95ae8e refactor(nodes): merge processors
Consolidate graph processing logic into session processor.

With graphs as the unit of work, and the session queue distributing graphs, we no longer need the invocation queue or processor.

Instead, the session processor dequeues the next session and processes it in a simple loop, greatly simplifying the app.

- Remove `graph_execution_manager` service.
- Remove `queue` (invocation queue) service.
- Remove `processor` (invocation processor) service.
- Remove queue-related logic from `Invoker`. It now only starts and stops the services, providing them with access to other services.
- Remove unused `invocation_retrieval_error` and `session_retrieval_error` events, these are no longer needed.
- Clean up stats service now that it is less coupled to the rest of the app.
- Refactor cancellation logic - cancellations now originate from session queue (i.e. HTTP cancel endpoint) and are emitted as events. Processor gets the events and sets the canceled event. Access to this event is provided to the invocation context for e.g. the step callback.
- Remove `sessions` router; it provided access to `graph_executions` but that no longer exists.
2024-02-29 13:28:20 -05:00
psychedelicious
0977a5e4aa tidy(nodes): remove no-op model_config
Because we now customize the JSON Schema creation for GraphExecutionState, the model_config did nothing.
2024-02-29 13:28:20 -05:00
psychedelicious
b711c46fa4 tidy(nodes): remove LibraryGraphs
The workflow library supersedes this unused feature.
2024-02-29 13:28:20 -05:00
psychedelicious
ab83fb2cea tidy(nodes): remove GraphInvocation
`GraphInvocation` is a node that can contain a whole graph. It is removed for a number of reasons:

1. This feature was unused (the UI doesn't support it) and there is no plan for it to be used.

The use-case it served is known in other node execution engines as "node groups" or "blocks" - a self-contained group of nodes, which has group inputs and outputs. This is a planned feature that will be handled client-side.

2. It adds substantial complexity to the graph processing logic. It's probably not enough to have a measurable performance impact but it does make it harder to work in the graph logic.

3. It allows for graphs to be recursive, and the improved invocations union handling does not play well with it. Actually, it works fine within `graph.py` but not in the tests for some reason. I do not understand why. There's probably a workaround, but I took this as encouragement to remove `GraphInvocation` from the app since we don't use it.
2024-02-29 13:28:20 -05:00
psychedelicious
d7adab89bd fix(nodes): fix OpenAPI schema generation
The change to `Graph.nodes` and `GraphExecutionState.results` validation requires some fanagling to get the OpenAPI schema generation to work. See new comments for a details.
2024-02-29 13:28:20 -05:00
psychedelicious
0ad904d2b3 feat(nodes): JIT graph nodes validation
We use pydantic to validate a union of valid invocations when instantiating a graph.

Previously, we constructed the union while creating the `Graph` class. This introduces a dependency on the order of imports.

For example, consider a setup where we have 3 invocations in the app:

- Python executes the module where `FirstInvocation` is defined, registering `FirstInvocation`.
- Python executes the module where `SecondInvocation` is defined, registering `SecondInvocation`.
- Python executes the module where `Graph` is defined. A union of invocations is created and used to define the `Graph.nodes` field. The union contains `FirstInvocation` and `SecondInvocation`.
- Python executes the module where `ThirdInvocation` is defined, registering `ThirdInvocation`.
- A graph is created that includes `ThirdInvocation`. Pydantic validates the graph using the union, which does not know about `ThirdInvocation`, raising a `ValidationError` about an unknown invocation type.

This scenario has been particularly problematic in tests, where we may create invocations dynamically. The test files have to be structured in such a way that the imports happen in the right order. It's a major pain.

This PR refactors the validation of graph nodes to resolve this issue:

- `BaseInvocation` gets a new method `get_typeadapter`. This builds a pydantic `TypeAdapter` for the union of all registered invocations, caching it after the first call.
- `Graph.nodes`'s type is widened to `dict[str, BaseInvocation]`. This actually is a nice bonus, because we get better type hints whenever we reference `some_graph.nodes`.
- A "plain" field validator takes over the validation logic for `Graph.nodes`. "Plain" validators totally override pydantic's own validation logic. The validator grabs the `TypeAdapter` from `BaseInvocation`, then validates each node with it. The validation is identical to the previous implementation - we get the same errors.

`BaseInvocationOutput` gets the same treatment.
2024-02-29 13:28:20 -05:00
dunkeroni
0bd0cfc025 one more redundant RGB convert removed 2024-02-29 13:28:20 -05:00
dunkeroni
9c2dd21256 chore: ruff formatting 2024-02-29 13:28:20 -05:00
dunkeroni
4b33589def chore(invocations): remove redundant RGB conversions 2024-02-29 13:28:20 -05:00
dunkeroni
3e5a91e3bf chore(invocations): use IMAGE_MODES constant literal 2024-02-29 13:28:20 -05:00
dunkeroni
2dd2f19b46 fix: removed custom module 2024-02-29 13:28:20 -05:00