From 903bd56c0a6ef2d503dd64d39f0eac00d14faa98 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 26 Oct 2016 13:20:41 +0200 Subject: [PATCH] [Feature] Allow to plan new periodics at different time --- src/lua/lua_config.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 10b64a8d0..915666a7d 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -2060,15 +2060,21 @@ lua_periodic_callback (gint unused_fd, short what, gpointer ud) lua_pop (L, 1); } else { - plan_more = lua_toboolean (L, -1); + if (lua_type (L, -1) == LUA_TBOOLEAN) { + plan_more = lua_toboolean (L, -1); + timeout = periodic->timeout; + } + else if (lua_type (L, -1) == LUA_TNUMBER) { + timeout = lua_tonumber (L, -1); + plan_more = timeout > 0 ? TRUE : FALSE; + } + lua_pop (L, 1); } event_del (&periodic->ev); if (plan_more) { - timeout = periodic->timeout; - if (periodic->need_jitter) { timeout = rspamd_time_jitter (timeout, 0.0); } @@ -2092,7 +2098,7 @@ lua_config_add_periodic (lua_State *L) struct rspamd_lua_periodic *periodic; gboolean need_jitter = FALSE; - if (cfg == NULL || timeout <= 0 || lua_type (L, 4) != LUA_TFUNCTION) { + if (cfg == NULL || timeout < 0 || lua_type (L, 4) != LUA_TFUNCTION) { return luaL_error (L, "invalid arguments"); } -- 2.39.5