Questions regarding Jobs

Hi everyone,

I’m currently using Orthanc to send DICOMs to a remove modality, which works fine with the ‘/modalities/XXX/store’ REST API. I’m using this in Asynchronous mode, so a job is created for the transfer and completed successfully afterward.

However, after the transfer is finished I would like to delete the resources from the Orthanc server and I’m currently wondering if there is a way to achieve this without separate book-keeping (e.g. storing the job ID in a database and periodically checking if it’s done to trigger the delete).

Ideally, I would like to create a delete job that waits for the previous store job to be finished and until it enters the success state, but I think this is not possible with Orthanc right now?

As an alternative, I’m considering just monitoring the ‘/jobs’ REST endpoint to basically implement a monitor of pending/succeeded store jobs that would trigger a delete whenever a succeeded store job is found. However, here I’m concerned that over time the list of jobs will become very large, so I’m wondering if there is any way to completely delete jobs from the list (API only says that there is Cancel/Pause/Resubmit/Resume) or for example only return the last let’s say 50 jobs when triggering ‘/jobs’ .

Are there any other maybe more simple ways one could use to delete resources after a store has been completed?

thanks in advance and happy holiday season
Martin

Hi Martin,

You could write a lua script (see https://book.orthanc-server.com/users/lua.html) or a python script (see https://book.orthanc-server.com/plugins/python.html?highlight=python) which would react to the OnJobSuccess event. In the callback, you would be able to filter the type of job (to process the c-store only) and delete the study.
Here is a portion of code which show exactly what I tried to describe: https://bitbucket.org/osimis/orthanc-setup-samples/src/5c99539fd30b419b97db32840a72374d285f5236/lua-samples/robust-forwarder.lua#lines-67

HTH,

I didn’t see anything about Job Events in the Python API documentation so I was under the impression that this is not supported.
After some digging, I have now found this example: https://bitbucket.org/osimis/orthanc-setup-samples/src/master/python-samples/job-retries.py
which should work just fine as a starting point.

That sounds as if it should do the trick,
thanks a lot!
Martin