Browse Source

[Minor] Lua_task: Add function to get scan time

tags/1.9.2
Vsevolod Stakhov 5 years ago
parent
commit
af11984981
1 changed files with 42 additions and 0 deletions
  1. 42
    0
      src/lua/lua_task.c

+ 42
- 0
src/lua/lua_task.c View File

@@ -696,7 +696,20 @@ 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:
@@ -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),
@@ -4401,6 +4415,34 @@ lua_task_get_timeval (lua_State *L)
return 1;
}

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)
{

Loading…
Cancel
Save