feat(api): return list of enqueued item ids when enqueuing

This commit is contained in:
psychedelicious
2025-06-28 16:07:40 +10:00
parent 2b1cffde5e
commit 3604dcfdd1
2 changed files with 14 additions and 0 deletions

View File

@@ -332,6 +332,7 @@ class EnqueueBatchResult(BaseModel):
requested: int = Field(description="The total number of queue items requested to be enqueued") requested: int = Field(description="The total number of queue items requested to be enqueued")
batch: Batch = Field(description="The batch that was enqueued") batch: Batch = Field(description="The batch that was enqueued")
priority: int = Field(description="The priority of the enqueued batch") priority: int = Field(description="The priority of the enqueued batch")
item_ids: list[int] = Field(description="The IDs of the queue items that were enqueued")
class RetryItemsResult(BaseModel): class RetryItemsResult(BaseModel):

View File

@@ -133,6 +133,18 @@ class SqliteSessionQueue(SessionQueueBase):
""", """,
values_to_insert, values_to_insert,
) )
with self._conn:
cursor = self._conn.cursor()
cursor.execute(
"""--sql
SELECT item_id
FROM session_queue
WHERE batch_id = ?
ORDER BY item_id DESC;
""",
(batch.batch_id,) # batch_id is the 4th element in the tuple
)
item_ids = [row[0] for row in cursor.fetchall()]
except Exception: except Exception:
raise raise
enqueue_result = EnqueueBatchResult( enqueue_result = EnqueueBatchResult(
@@ -141,6 +153,7 @@ class SqliteSessionQueue(SessionQueueBase):
enqueued=enqueued_count, enqueued=enqueued_count,
batch=batch, batch=batch,
priority=priority, priority=priority,
item_ids=item_ids,
) )
self.__invoker.services.events.emit_batch_enqueued(enqueue_result) self.__invoker.services.events.emit_batch_enqueued(enqueue_result)
return enqueue_result return enqueue_result