changeset 864:035fe50b2e00

heartbeat
author Alain Mazy <am@osimis.io>
date Thu, 30 Jun 2022 20:34:43 +0200
parents 6445d9729c45
children ae2002f69694
files Sphinx/source/users/lua.rst
diffstat 1 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Sphinx/source/users/lua.rst	Thu Jun 30 20:22:13 2022 +0200
+++ b/Sphinx/source/users/lua.rst	Thu Jun 30 20:34:43 2022 +0200
@@ -252,6 +252,12 @@
 * ``HttpDelete(url, headers)``
 * ``SetHttpCredentials(username, password)`` can be used to setup the
   HTTP credentials.
+* ``SetHttpTimeout(timeout)`` can be used to configure a timeout (in seconds).
+  When contacting an external webservice, it is recommended to configure a very
+  short timeout not to lock the Lua context for too long.  No other Lua callbacks
+  may be run at the same time which may have a significant impact on Orthanc
+  responsivness in general.
+  
 
 The ``headers`` argument is optional and was added in release
 1.2.1. It allows to set the HTTP headers for the HTTP client request.
@@ -262,6 +268,9 @@
    local headers = {
       ["content-type"] = "image/png",
    }
+
+   SetHttpCredentials('user', 'pwd')
+   SetHttpTimeout(1)
    HttpPost("http://localhost/my-web-service/instance-preview", preview, headers)
 
 .. _lua-origin:
@@ -597,6 +606,24 @@
   end
 
 
+HeartBeat
+---------
+
+.. highlight:: lua
+
+Starting from Orthanc 1.11.1, one can run a Lua callback at regular 
+interval.  This interval is defined in the ``LuaHeartBeatPeriod``
+configuration::
+
+  function OnHeartBeat() 
+    
+    -- ping a webservice to notify that Orthanc is still alive
+    SetHttpCredentials('user', 'pwd')
+    SetHttpTimeout(1)
+    HttpPost("http://localhost/my-web-service/still-alive", "my-id", {})
+
+  end
+
 .. _lua-external-modules:
 
 Using external modules