summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-04-15 12:21:21 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-04-15 12:21:21 +0100
commitaf11984981e82ce69486d30606214424e244a804 (patch)
treee2ec696ed6551a53af842e630499f4054ff9781d
parent6861c93af2e50b118e3c4a3609f72a90c790c184 (diff)
downloadrspamd-af11984981e82ce69486d30606214424e244a804.tar.gz
rspamd-af11984981e82ce69486d30606214424e244a804.zip
[Minor] Lua_task: Add function to get scan time
-rw-r--r--src/lua/lua_task.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index 7bc4438cd..b1aabfdda 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -696,8 +696,21 @@ LUA_FUNCTION_DEF (task, get_date);
* @return {string} if of a message
*/
LUA_FUNCTION_DEF (task, get_message_id);
+/***
+ * @method task:get_timeval()
+ * Returns the timestamp for a task start processing time.
+ * @return {table} table with fields as described in `struct timeval` in C
+ */
LUA_FUNCTION_DEF (task, get_timeval);
/***
+ * @method task:get_scan_time([set])
+ * Returns 2 floating point numbers: scan real time and scan virtual time.
+ * If `set` is `true`, then the finishing time is also set (enabled by default).
+ * This function should be normally called on idempotent phase.
+ * @return {number,number} real and virtual times in seconds with floating point
+ */
+LUA_FUNCTION_DEF (task, get_scan_time);
+/***
* @method task:get_metric_result()
* Get full result of a metric as a table:
* - `score`: current score
@@ -1102,6 +1115,7 @@ static const struct luaL_reg tasklib_m[] = {
LUA_INTERFACE_DEF (task, get_date),
LUA_INTERFACE_DEF (task, get_message_id),
LUA_INTERFACE_DEF (task, get_timeval),
+ LUA_INTERFACE_DEF (task, get_scan_time),
LUA_INTERFACE_DEF (task, get_metric_result),
LUA_INTERFACE_DEF (task, get_metric_score),
LUA_INTERFACE_DEF (task, get_metric_action),
@@ -4402,6 +4416,34 @@ lua_task_get_timeval (lua_State *L)
}
static gint
+lua_task_get_scan_time (lua_State *L)
+{
+ LUA_TRACE_POINT;
+ struct rspamd_task *task = lua_check_task (L, 1);
+ gboolean set = TRUE;
+
+ if (task != NULL) {
+ if (lua_isboolean (L, 2)) {
+ set = lua_toboolean (L, 2);
+ }
+
+ rspamd_task_set_finish_time (task);
+ lua_pushnumber (L, task->time_real_finish - task->time_real);
+ lua_pushnumber (L, task->time_virtual_finish - task->time_virtual);
+
+ if (!set) {
+ /* Reset to nan to allow further calcs in rspamd_task_set_finish_time */
+ task->time_real_finish = NAN;
+ }
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 1;
+}
+
+static gint
lua_task_get_size (lua_State *L)
{
LUA_TRACE_POINT;