Mercurial > hg > orthanc-book
changeset 1199:fc98b7b10d47
kvs: Reserve + Acknowledge
| author | Alain Mazy <am@orthanc.team> |
|---|---|
| date | Tue, 14 Oct 2025 15:36:09 +0200 |
| parents | ad089b8324a7 |
| children | cfd5b7689c72 |
| files | Sphinx/source/plugins/python/queues-and-kvs.py |
| diffstat | 1 files changed, 8 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/Sphinx/source/plugins/python/queues-and-kvs.py Fri Oct 03 16:21:24 2025 +0200 +++ b/Sphinx/source/plugins/python/queues-and-kvs.py Tue Oct 14 15:36:09 2025 +0200 @@ -13,7 +13,8 @@ while is_worker_running: # get messages from the queue named "instances-to-process" that is stored in Orthanc DB. # Get the message from the FRONT for FIFO and from the BACK for a LIFO - message = orthanc.DequeueValue("instances-to-process", orthanc.QueueOrigin.FRONT) + # from v7.0, prefer the ReserveQueueValue message = orthanc.DequeueValue("instances-to-process", orthanc.QueueOrigin.FRONT) + message, messageId = orthanc.ReserveQueueValue("instances-to-process", orthanc.QueueOrigin.FRONT, 2) if message is None: # no messages in the queue @@ -21,6 +22,7 @@ else: payload = json.loads(message.decode('utf-8')) resourceId = payload["resource-id"] + orthanc.LogInfo(f"processing resource {resourceId}") # get the value associated to the key resourceId in the "my-store" Key Value Store. @@ -31,6 +33,10 @@ orthanc.LogInfo(f"Value for resource {resourceId} is {value.decode('utf-8')}") orthanc.DeleteKeyValue("my-store", resourceId) + orthanc.RestApiPut(f"/studies/{payload['study-id']}/labels/{payload['my-data']}", b"") + # mark the processing as complete (new in v7.0) + orthanc.AcknowledgeQueueValue("instances-to-process", messageId) + def OnChange(changeType, level, resource: str): global worker_thread @@ -40,6 +46,7 @@ processPayload = { "resource-id": resource, + "study-id": json.loads(orthanc.RestApiGet(f"/instances/{resource}/study"))["ID"], "my-data": "my-data" }
