From 99ff1c8add46cf0f32610ee8145ea3fe20654c5e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 19 Mar 2019 12:15:41 +0000 Subject: [PATCH] [Fix] Fix finishing script for clickhouse collection --- src/plugins/lua/clickhouse.lua | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/plugins/lua/clickhouse.lua b/src/plugins/lua/clickhouse.lua index 65555c7a2..a9caa5292 100644 --- a/src/plugins/lua/clickhouse.lua +++ b/src/plugins/lua/clickhouse.lua @@ -242,13 +242,14 @@ local function clickhouse_check_symbol(task, symbols, need_score) return false end -local function clickhouse_send_data(task) +local function clickhouse_send_data(task, ev_base) + local log_object = task or rspamd_config local upstream = settings.upstream:get_upstream_round_robin() local ip_addr = upstream:get_addr():to_string(true) local function gen_success_cb(what, how_many) return function (_, _) - rspamd_logger.infox(task, "sent %s rows of %s to clickhouse server %s", + rspamd_logger.infox(log_object, "sent %s rows of %s to clickhouse server %s", how_many, what, ip_addr) upstream:ok() end @@ -256,23 +257,27 @@ local function clickhouse_send_data(task) local function gen_fail_cb(what, how_many) return function (_, err) - rspamd_logger.errx(task, "cannot send %s rows of %s data to clickhouse server %s: %s", + rspamd_logger.errx(log_object, "cannot send %s rows of %s data to clickhouse server %s: %s", how_many, what, ip_addr, err) upstream:fail() end end local function send_data(what, tbl, query) - local ch_params = { - task = task, - } + local ch_params = {} + if task then + ch_params.task = task + else + ch_params.config = rspamd_config + ch_params.ev_base = ev_base + end local ret = lua_clickhouse.insert(upstream, settings, ch_params, query, tbl, gen_success_cb(what, #tbl), gen_fail_cb(what, #tbl)) if not ret then - rspamd_logger.errx(task, "cannot send %s rows of %s data to clickhouse server %s: %s", + rspamd_logger.errx(log_object, "cannot send %s rows of %s data to clickhouse server %s: %s", #tbl, what, ip_addr, 'cannot make HTTP request') end end @@ -927,9 +932,9 @@ if opts then priority = 10, flags = 'empty,explicit_disable,ignore_passthrough', }) - rspamd_config:register_finish_script(function(task) + rspamd_config:register_finish_script(function(_, ev_base, _) if nrows > 0 then - clickhouse_send_data(task) + clickhouse_send_data(nil, ev_base) end end) -- Create tables on load -- 2.39.5