Orthanc Scheduler like a crontab

Hi Authors,

Is there a way in Orthanc to create a scheduler (like a crontab in unix or Schedule annotation in Java Srping) ? For example, in Java spring we used to be having this annotation

@Scheduled(cron = "0/20 * * * * ?")
public void monitorStorage() throws APIException {

It does mean that the function monitorStoreage() is calling after each 20 seconds. I guest I can mimic that functionality in OrthanC by defining a job and inside that job create the same job again and again. But I guest vaguely that could hurt the performance of the main Orthanc since there are a limited jobs configured in the Configuration file and other jobs like: processing dicom, http wado rs, delete resources should be first prioritized. Can you please share your experience ?

Thanks,
Phong

Hello,

Orthanc jobs must not be used for this purpose. A job shouldn’t be thought of as a thread (despite it is executed by a thread).

The Orthanc scheduler assumes a job is a single pack of intensive operations (CPU and/or I/O) that are scheduled for execution in the future. A Orthanc job must be independent from the other jobs (it can only possibly schedule new jobs), and it must not wait in an idle state. As you guessed, implementing a scheduler as an Orthanc job would strongly hurt performance.

You actually want to implement a C/C++ plugin. Plugins live in a separate world than the Orthanc scheduler, and can start/stop threads at their will:
https://book.orthanc-server.com/developers/creating-plugins.html

Now, in your case, you are most probably interested in the recently-released Python plugin:
https://book.orthanc-server.com/plugins/python.html

I have just added a sample showing how to achieve your goal in a few lines of self-explaining Python code:
https://book.orthanc-server.com/plugins/python.html#scheduling-a-task-for-periodic-execution

HTH,
Sébastien-

Thank you Sébastien,
Yes I am developing my own C++ plugin. So with tor info I guess I should create my own separate thread for running the scheduler.