From 2c868bb0a46ae17d6017f889b6aae6f136d9fb1e Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 29 Jan 2019 11:37:13 +0000 Subject: [PATCH] [Minor] Elastic: Switch off coroutines as they are unstable --- src/plugins/lua/elastic.lua | 38 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/plugins/lua/elastic.lua b/src/plugins/lua/elastic.lua index a223756e4..935768497 100644 --- a/src/plugins/lua/elastic.lua +++ b/src/plugins/lua/elastic.lua @@ -79,12 +79,30 @@ local function elastic_send_data(task) local push_url = connect_prefix .. ip_addr .. '/'..es_index..'/_bulk' local bulk_json = table.concat(tbl, "\n") - local err, response = rspamd_http.request({ + + local function http_callback(err, code, _, _) + if err then + rspamd_logger.infox(task, "cannot push data to elastic backend (%s): %s; failed attempts: %s/%s", + push_url, err, failed_sends, settings.max_fail) + else + if code ~= 200 then + rspamd_logger.infox(task, + "cannot push data to elastic backend (%s): wrong http code %s (%s); failed attempts: %s/%s", + push_url, err, code, failed_sends, settings.max_fail) + else + lua_util.debugm(N, task, "successfully sent %s (%s bytes) rows to ES", + nrows, #bulk_json) + end + end + end + + rspamd_http.request({ url = push_url, headers = { ['Content-Type'] = 'application/x-ndjson', }, body = bulk_json, + callback = http_callback, task = task, method = 'post', gzip = settings.use_gzip, @@ -93,24 +111,6 @@ local function elastic_send_data(task) password = settings.password, timeout = settings.timeout, }) - - if err then - rspamd_logger.infox(task, "cannot push data to elastic backend (%s): %s; failed attempts: %s/%s", - push_url, err, failed_sends, settings.max_fail) - else - if response.code ~= 200 then - rspamd_logger.infox(task, - "cannot push data to elastic backend (%s): wrong http code %s (%s); failed attempts: %s/%s", - push_url, err, response.code, failed_sends, settings.max_fail) - else - lua_util.debugm(N, task, "successfully sent %s (%s bytes) rows to ES", - nrows, #bulk_json) - - return true - end - end - - return false end local function get_general_metadata(task) -- 2.39.5