Mercurial > hg > orthanc-book
comparison Sphinx/source/users/lua.rst @ 864:035fe50b2e00
heartbeat
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 30 Jun 2022 20:34:43 +0200 |
parents | 2f8ee0aef0a6 |
children | dbe3fd98beb0 |
comparison
equal
deleted
inserted
replaced
863:6445d9729c45 | 864:035fe50b2e00 |
---|---|
250 * ``HttpPost(url, body, headers)`` | 250 * ``HttpPost(url, body, headers)`` |
251 * ``HttpPut(url, body, headers)`` | 251 * ``HttpPut(url, body, headers)`` |
252 * ``HttpDelete(url, headers)`` | 252 * ``HttpDelete(url, headers)`` |
253 * ``SetHttpCredentials(username, password)`` can be used to setup the | 253 * ``SetHttpCredentials(username, password)`` can be used to setup the |
254 HTTP credentials. | 254 HTTP credentials. |
255 * ``SetHttpTimeout(timeout)`` can be used to configure a timeout (in seconds). | |
256 When contacting an external webservice, it is recommended to configure a very | |
257 short timeout not to lock the Lua context for too long. No other Lua callbacks | |
258 may be run at the same time which may have a significant impact on Orthanc | |
259 responsivness in general. | |
260 | |
255 | 261 |
256 The ``headers`` argument is optional and was added in release | 262 The ``headers`` argument is optional and was added in release |
257 1.2.1. It allows to set the HTTP headers for the HTTP client request. | 263 1.2.1. It allows to set the HTTP headers for the HTTP client request. |
258 | 264 |
259 Example:: | 265 Example:: |
260 | 266 |
261 local preview = RestApiGet('/instances/' .. instanceId .. '/preview') | 267 local preview = RestApiGet('/instances/' .. instanceId .. '/preview') |
262 local headers = { | 268 local headers = { |
263 ["content-type"] = "image/png", | 269 ["content-type"] = "image/png", |
264 } | 270 } |
271 | |
272 SetHttpCredentials('user', 'pwd') | |
273 SetHttpTimeout(1) | |
265 HttpPost("http://localhost/my-web-service/instance-preview", preview, headers) | 274 HttpPost("http://localhost/my-web-service/instance-preview", preview, headers) |
266 | 275 |
267 .. _lua-origin: | 276 .. _lua-origin: |
268 | 277 |
269 Origin of the instances | 278 Origin of the instances |
595 | 604 |
596 return query | 605 return query |
597 end | 606 end |
598 | 607 |
599 | 608 |
609 HeartBeat | |
610 --------- | |
611 | |
612 .. highlight:: lua | |
613 | |
614 Starting from Orthanc 1.11.1, one can run a Lua callback at regular | |
615 interval. This interval is defined in the ``LuaHeartBeatPeriod`` | |
616 configuration:: | |
617 | |
618 function OnHeartBeat() | |
619 | |
620 -- ping a webservice to notify that Orthanc is still alive | |
621 SetHttpCredentials('user', 'pwd') | |
622 SetHttpTimeout(1) | |
623 HttpPost("http://localhost/my-web-service/still-alive", "my-id", {}) | |
624 | |
625 end | |
626 | |
600 .. _lua-external-modules: | 627 .. _lua-external-modules: |
601 | 628 |
602 Using external modules | 629 Using external modules |
603 ---------------------- | 630 ---------------------- |
604 | 631 |