]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: hlua/event_hdl: timestamp for events
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 20 Apr 2023 09:32:46 +0000 (11:32 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 21 Apr 2023 12:36:45 +0000 (14:36 +0200)
'when' optional argument is provided to lua event handlers.

It is an integer representing the number of seconds elapsed since Epoch
and may be used in conjunction with lua `os.date()` function to provide
a custom format string.

doc/lua-api/index.rst
src/hlua.c

index 1bb49978dc03b2e5fb4bb9552d40938f3124ccb1..ee30b73a297ca2b4a017f74d1646e33cd7cf45f5 100644 (file)
@@ -942,12 +942,16 @@ Core class
 
 .. code-block:: lua
 
-    function(event, event_data, sub)
+    function(event, event_data, sub, when)
 ..
 
   * **event** (*string*): the event type (one of the **event_types** you specified when subscribing)
   * **event_data**: specific to each event family (For **SERVER** family, a :ref:`server_event_class` object)
   * **sub**: class to manage the subscription from within the event (a :ref:`event_sub_class` object)
+  * **when**: timestamp corresponding to the date when the event was generated.
+    It is an integer representing the number of seconds elapsed since Epoch.
+    It may be provided as optional argument to `os.date()` lua function to
+    convert it to a string according to a given format string.
 
   .. Warning::
     The callback function will only be scheduled on the very same thread that
index a20ab03fade48a72eb234c821a4882d465deeb13..5c29bc5ac1402616d59ea3cd6be3734f4337bdaf 100644 (file)
@@ -9087,6 +9087,10 @@ __LJMP static void hlua_event_hdl_cb_push_args(struct hlua_event_sub *hlua_sub,
        /* sub mgmt */
        hlua->nargs += 1;
        hlua_fcn_new_event_sub(hlua->T, hlua_sub->sub);
+
+       /* when? */
+       hlua->nargs += 1;
+       lua_pushinteger(hlua->T, e->when.tv_sec);
 }
 
 /* events runner: if there's an ongoing hlua event handling process, finish it