Skip to content

Commit 186687e

Browse files
Merge branch 'main' into cursor/manage-model-switching-and-error-states-8a4e
2 parents f2cc3a1 + 7ea343c commit 186687e

File tree

248 files changed

+13176
-11863
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+13176
-11863
lines changed

.github/actions/install-frontend-deps/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ description: Installs frontend dependencies with pnpm, with caching
33
runs:
44
using: 'composite'
55
steps:
6-
- name: setup node 18
6+
- name: setup node 20
77
uses: actions/setup-node@v4
88
with:
9-
node-version: '18'
9+
node-version: '20'
1010

1111
- name: setup pnpm
1212
uses: pnpm/action-setup@v4
1313
with:
14-
version: 8.15.6
14+
version: 10
1515
run_install: false
1616

1717
- name: get pnpm store directory

invokeai/app/api/routers/session_queue.py

Lines changed: 116 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Optional
22

3-
from fastapi import Body, Path, Query
3+
from fastapi import Body, HTTPException, Path, Query
44
from fastapi.routing import APIRouter
55
from pydantic import BaseModel, Field
66

@@ -22,6 +22,7 @@
2222
RetryItemsResult,
2323
SessionQueueCountsByDestination,
2424
SessionQueueItem,
25+
SessionQueueItemNotFoundError,
2526
SessionQueueStatus,
2627
)
2728
from invokeai.app.services.shared.pagination import CursorPaginatedResults
@@ -59,10 +60,12 @@ async def enqueue_batch(
5960
),
6061
) -> EnqueueBatchResult:
6162
"""Processes a batch and enqueues the output graphs for execution."""
62-
63-
return await ApiDependencies.invoker.services.session_queue.enqueue_batch(
64-
queue_id=queue_id, batch=batch, prepend=prepend
65-
)
63+
try:
64+
return await ApiDependencies.invoker.services.session_queue.enqueue_batch(
65+
queue_id=queue_id, batch=batch, prepend=prepend
66+
)
67+
except Exception as e:
68+
raise HTTPException(status_code=500, detail=f"Unexpected error while enqueuing batch: {e}")
6669

6770

6871
@session_queue_router.get(
@@ -82,14 +85,17 @@ async def list_queue_items(
8285
) -> CursorPaginatedResults[SessionQueueItem]:
8386
"""Gets cursor-paginated queue items"""
8487

85-
return ApiDependencies.invoker.services.session_queue.list_queue_items(
86-
queue_id=queue_id,
87-
limit=limit,
88-
status=status,
89-
cursor=cursor,
90-
priority=priority,
91-
destination=destination,
92-
)
88+
try:
89+
return ApiDependencies.invoker.services.session_queue.list_queue_items(
90+
queue_id=queue_id,
91+
limit=limit,
92+
status=status,
93+
cursor=cursor,
94+
priority=priority,
95+
destination=destination,
96+
)
97+
except Exception as e:
98+
raise HTTPException(status_code=500, detail=f"Unexpected error while listing all items: {e}")
9399

94100

95101
@session_queue_router.get(
@@ -104,11 +110,13 @@ async def list_all_queue_items(
104110
destination: Optional[str] = Query(default=None, description="The destination of queue items to fetch"),
105111
) -> list[SessionQueueItem]:
106112
"""Gets all queue items"""
107-
108-
return ApiDependencies.invoker.services.session_queue.list_all_queue_items(
109-
queue_id=queue_id,
110-
destination=destination,
111-
)
113+
try:
114+
return ApiDependencies.invoker.services.session_queue.list_all_queue_items(
115+
queue_id=queue_id,
116+
destination=destination,
117+
)
118+
except Exception as e:
119+
raise HTTPException(status_code=500, detail=f"Unexpected error while listing all queue items: {e}")
112120

113121

114122
@session_queue_router.put(
@@ -120,7 +128,10 @@ async def resume(
120128
queue_id: str = Path(description="The queue id to perform this operation on"),
121129
) -> SessionProcessorStatus:
122130
"""Resumes session processor"""
123-
return ApiDependencies.invoker.services.session_processor.resume()
131+
try:
132+
return ApiDependencies.invoker.services.session_processor.resume()
133+
except Exception as e:
134+
raise HTTPException(status_code=500, detail=f"Unexpected error while resuming queue: {e}")
124135

125136

126137
@session_queue_router.put(
@@ -132,7 +143,10 @@ async def Pause(
132143
queue_id: str = Path(description="The queue id to perform this operation on"),
133144
) -> SessionProcessorStatus:
134145
"""Pauses session processor"""
135-
return ApiDependencies.invoker.services.session_processor.pause()
146+
try:
147+
return ApiDependencies.invoker.services.session_processor.pause()
148+
except Exception as e:
149+
raise HTTPException(status_code=500, detail=f"Unexpected error while pausing queue: {e}")
136150

137151

138152
@session_queue_router.put(
@@ -144,7 +158,10 @@ async def cancel_all_except_current(
144158
queue_id: str = Path(description="The queue id to perform this operation on"),
145159
) -> CancelAllExceptCurrentResult:
146160
"""Immediately cancels all queue items except in-processing items"""
147-
return ApiDependencies.invoker.services.session_queue.cancel_all_except_current(queue_id=queue_id)
161+
try:
162+
return ApiDependencies.invoker.services.session_queue.cancel_all_except_current(queue_id=queue_id)
163+
except Exception as e:
164+
raise HTTPException(status_code=500, detail=f"Unexpected error while canceling all except current: {e}")
148165

149166

150167
@session_queue_router.put(
@@ -156,7 +173,10 @@ async def delete_all_except_current(
156173
queue_id: str = Path(description="The queue id to perform this operation on"),
157174
) -> DeleteAllExceptCurrentResult:
158175
"""Immediately deletes all queue items except in-processing items"""
159-
return ApiDependencies.invoker.services.session_queue.delete_all_except_current(queue_id=queue_id)
176+
try:
177+
return ApiDependencies.invoker.services.session_queue.delete_all_except_current(queue_id=queue_id)
178+
except Exception as e:
179+
raise HTTPException(status_code=500, detail=f"Unexpected error while deleting all except current: {e}")
160180

161181

162182
@session_queue_router.put(
@@ -169,7 +189,12 @@ async def cancel_by_batch_ids(
169189
batch_ids: list[str] = Body(description="The list of batch_ids to cancel all queue items for", embed=True),
170190
) -> CancelByBatchIDsResult:
171191
"""Immediately cancels all queue items from the given batch ids"""
172-
return ApiDependencies.invoker.services.session_queue.cancel_by_batch_ids(queue_id=queue_id, batch_ids=batch_ids)
192+
try:
193+
return ApiDependencies.invoker.services.session_queue.cancel_by_batch_ids(
194+
queue_id=queue_id, batch_ids=batch_ids
195+
)
196+
except Exception as e:
197+
raise HTTPException(status_code=500, detail=f"Unexpected error while canceling by batch id: {e}")
173198

174199

175200
@session_queue_router.put(
@@ -182,9 +207,12 @@ async def cancel_by_destination(
182207
destination: str = Query(description="The destination to cancel all queue items for"),
183208
) -> CancelByDestinationResult:
184209
"""Immediately cancels all queue items with the given origin"""
185-
return ApiDependencies.invoker.services.session_queue.cancel_by_destination(
186-
queue_id=queue_id, destination=destination
187-
)
210+
try:
211+
return ApiDependencies.invoker.services.session_queue.cancel_by_destination(
212+
queue_id=queue_id, destination=destination
213+
)
214+
except Exception as e:
215+
raise HTTPException(status_code=500, detail=f"Unexpected error while canceling by destination: {e}")
188216

189217

190218
@session_queue_router.put(
@@ -197,7 +225,10 @@ async def retry_items_by_id(
197225
item_ids: list[int] = Body(description="The queue item ids to retry"),
198226
) -> RetryItemsResult:
199227
"""Immediately cancels all queue items with the given origin"""
200-
return ApiDependencies.invoker.services.session_queue.retry_items_by_id(queue_id=queue_id, item_ids=item_ids)
228+
try:
229+
return ApiDependencies.invoker.services.session_queue.retry_items_by_id(queue_id=queue_id, item_ids=item_ids)
230+
except Exception as e:
231+
raise HTTPException(status_code=500, detail=f"Unexpected error while retrying queue items: {e}")
201232

202233

203234
@session_queue_router.put(
@@ -211,11 +242,14 @@ async def clear(
211242
queue_id: str = Path(description="The queue id to perform this operation on"),
212243
) -> ClearResult:
213244
"""Clears the queue entirely, immediately canceling the currently-executing session"""
214-
queue_item = ApiDependencies.invoker.services.session_queue.get_current(queue_id)
215-
if queue_item is not None:
216-
ApiDependencies.invoker.services.session_queue.cancel_queue_item(queue_item.item_id)
217-
clear_result = ApiDependencies.invoker.services.session_queue.clear(queue_id)
218-
return clear_result
245+
try:
246+
queue_item = ApiDependencies.invoker.services.session_queue.get_current(queue_id)
247+
if queue_item is not None:
248+
ApiDependencies.invoker.services.session_queue.cancel_queue_item(queue_item.item_id)
249+
clear_result = ApiDependencies.invoker.services.session_queue.clear(queue_id)
250+
return clear_result
251+
except Exception as e:
252+
raise HTTPException(status_code=500, detail=f"Unexpected error while clearing queue: {e}")
219253

220254

221255
@session_queue_router.put(
@@ -229,7 +263,10 @@ async def prune(
229263
queue_id: str = Path(description="The queue id to perform this operation on"),
230264
) -> PruneResult:
231265
"""Prunes all completed or errored queue items"""
232-
return ApiDependencies.invoker.services.session_queue.prune(queue_id)
266+
try:
267+
return ApiDependencies.invoker.services.session_queue.prune(queue_id)
268+
except Exception as e:
269+
raise HTTPException(status_code=500, detail=f"Unexpected error while pruning queue: {e}")
233270

234271

235272
@session_queue_router.get(
@@ -243,7 +280,10 @@ async def get_current_queue_item(
243280
queue_id: str = Path(description="The queue id to perform this operation on"),
244281
) -> Optional[SessionQueueItem]:
245282
"""Gets the currently execution queue item"""
246-
return ApiDependencies.invoker.services.session_queue.get_current(queue_id)
283+
try:
284+
return ApiDependencies.invoker.services.session_queue.get_current(queue_id)
285+
except Exception as e:
286+
raise HTTPException(status_code=500, detail=f"Unexpected error while getting current queue item: {e}")
247287

248288

249289
@session_queue_router.get(
@@ -257,7 +297,10 @@ async def get_next_queue_item(
257297
queue_id: str = Path(description="The queue id to perform this operation on"),
258298
) -> Optional[SessionQueueItem]:
259299
"""Gets the next queue item, without executing it"""
260-
return ApiDependencies.invoker.services.session_queue.get_next(queue_id)
300+
try:
301+
return ApiDependencies.invoker.services.session_queue.get_next(queue_id)
302+
except Exception as e:
303+
raise HTTPException(status_code=500, detail=f"Unexpected error while getting next queue item: {e}")
261304

262305

263306
@session_queue_router.get(
@@ -271,9 +314,12 @@ async def get_queue_status(
271314
queue_id: str = Path(description="The queue id to perform this operation on"),
272315
) -> SessionQueueAndProcessorStatus:
273316
"""Gets the status of the session queue"""
274-
queue = ApiDependencies.invoker.services.session_queue.get_queue_status(queue_id)
275-
processor = ApiDependencies.invoker.services.session_processor.get_status()
276-
return SessionQueueAndProcessorStatus(queue=queue, processor=processor)
317+
try:
318+
queue = ApiDependencies.invoker.services.session_queue.get_queue_status(queue_id)
319+
processor = ApiDependencies.invoker.services.session_processor.get_status()
320+
return SessionQueueAndProcessorStatus(queue=queue, processor=processor)
321+
except Exception as e:
322+
raise HTTPException(status_code=500, detail=f"Unexpected error while getting queue status: {e}")
277323

278324

279325
@session_queue_router.get(
@@ -288,7 +334,10 @@ async def get_batch_status(
288334
batch_id: str = Path(description="The batch to get the status of"),
289335
) -> BatchStatus:
290336
"""Gets the status of the session queue"""
291-
return ApiDependencies.invoker.services.session_queue.get_batch_status(queue_id=queue_id, batch_id=batch_id)
337+
try:
338+
return ApiDependencies.invoker.services.session_queue.get_batch_status(queue_id=queue_id, batch_id=batch_id)
339+
except Exception as e:
340+
raise HTTPException(status_code=500, detail=f"Unexpected error while getting batch status: {e}")
292341

293342

294343
@session_queue_router.get(
@@ -304,7 +353,12 @@ async def get_queue_item(
304353
item_id: int = Path(description="The queue item to get"),
305354
) -> SessionQueueItem:
306355
"""Gets a queue item"""
307-
return ApiDependencies.invoker.services.session_queue.get_queue_item(item_id)
356+
try:
357+
return ApiDependencies.invoker.services.session_queue.get_queue_item(item_id)
358+
except SessionQueueItemNotFoundError:
359+
raise HTTPException(status_code=404, detail=f"Queue item with id {item_id} not found in queue {queue_id}")
360+
except Exception as e:
361+
raise HTTPException(status_code=500, detail=f"Unexpected error while fetching queue item: {e}")
308362

309363

310364
@session_queue_router.delete(
@@ -316,7 +370,10 @@ async def delete_queue_item(
316370
item_id: int = Path(description="The queue item to delete"),
317371
) -> None:
318372
"""Deletes a queue item"""
319-
ApiDependencies.invoker.services.session_queue.delete_queue_item(item_id)
373+
try:
374+
ApiDependencies.invoker.services.session_queue.delete_queue_item(item_id)
375+
except Exception as e:
376+
raise HTTPException(status_code=500, detail=f"Unexpected error while deleting queue item: {e}")
320377

321378

322379
@session_queue_router.put(
@@ -331,8 +388,12 @@ async def cancel_queue_item(
331388
item_id: int = Path(description="The queue item to cancel"),
332389
) -> SessionQueueItem:
333390
"""Deletes a queue item"""
334-
335-
return ApiDependencies.invoker.services.session_queue.cancel_queue_item(item_id)
391+
try:
392+
return ApiDependencies.invoker.services.session_queue.cancel_queue_item(item_id)
393+
except SessionQueueItemNotFoundError:
394+
raise HTTPException(status_code=404, detail=f"Queue item with id {item_id} not found in queue {queue_id}")
395+
except Exception as e:
396+
raise HTTPException(status_code=500, detail=f"Unexpected error while canceling queue item: {e}")
336397

337398

338399
@session_queue_router.get(
@@ -345,9 +406,12 @@ async def counts_by_destination(
345406
destination: str = Query(description="The destination to query"),
346407
) -> SessionQueueCountsByDestination:
347408
"""Gets the counts of queue items by destination"""
348-
return ApiDependencies.invoker.services.session_queue.get_counts_by_destination(
349-
queue_id=queue_id, destination=destination
350-
)
409+
try:
410+
return ApiDependencies.invoker.services.session_queue.get_counts_by_destination(
411+
queue_id=queue_id, destination=destination
412+
)
413+
except Exception as e:
414+
raise HTTPException(status_code=500, detail=f"Unexpected error while fetching counts by destination: {e}")
351415

352416

353417
@session_queue_router.delete(
@@ -360,6 +424,9 @@ async def delete_by_destination(
360424
destination: str = Path(description="The destination to query"),
361425
) -> DeleteByDestinationResult:
362426
"""Deletes all items with the given destination"""
363-
return ApiDependencies.invoker.services.session_queue.delete_by_destination(
364-
queue_id=queue_id, destination=destination
365-
)
427+
try:
428+
return ApiDependencies.invoker.services.session_queue.delete_by_destination(
429+
queue_id=queue_id, destination=destination
430+
)
431+
except Exception as e:
432+
raise HTTPException(status_code=500, detail=f"Unexpected error while deleting by destination: {e}")

0 commit comments

Comments
 (0)