diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-12-07 13:56:03 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-12-07 13:56:03 +0000 |
commit | 3a7f4ef0ed9fb2583387c0fbcc7fc28ab403b3bc (patch) | |
tree | 150786e208b00946a380ab34da5acfc2c29f08a9 /lualib | |
parent | 02757e6d2af733367cb870fa2a24ceb505954f0e (diff) | |
download | rspamd-3a7f4ef0ed9fb2583387c0fbcc7fc28ab403b3bc.tar.gz rspamd-3a7f4ef0ed9fb2583387c0fbcc7fc28ab403b3bc.zip |
[Minor] Add initial stat callback
Diffstat (limited to 'lualib')
-rw-r--r-- | lualib/lua_bayes_redis.lua | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lualib/lua_bayes_redis.lua b/lualib/lua_bayes_redis.lua index 25c56d58b..575beff4b 100644 --- a/lualib/lua_bayes_redis.lua +++ b/lualib/lua_bayes_redis.lua @@ -21,7 +21,7 @@ local lua_redis = require "lua_redis" local logger = require "rspamd_logger" local lua_util = require "lua_util" -local N = "stat_redis" +local N = "bayes" local function gen_classify_functor(redis_params, classify_script_id) return function(task, expanded_key, id, is_spam, stat_tokens, callback) @@ -52,7 +52,7 @@ end --- @param classifier_ucl ucl of the classifier config --- @param statfile_ucl ucl of the statfile config --- @return a pair of (classify_functor, learn_functor) or `nil` in case of error -exports.lua_bayes_init_classifier = function(classifier_ucl, statfile_ucl) +exports.lua_bayes_init_classifier = function(classifier_ucl, statfile_ucl, symbol, stat_periodic_cb) local redis_params if classifier_ucl.backend then @@ -78,6 +78,24 @@ exports.lua_bayes_init_classifier = function(classifier_ucl, statfile_ucl) local classify_script_id = lua_redis.load_redis_script_from_file("bayes_classify.lua", redis_params) local learn_script_id = lua_redis.load_redis_script_from_file("bayes_learn.lua", redis_params) + local stat_script_id = lua_redis.load_redis_script_from_file("bayes_stat.lua", redis_params) + local max_users = classifier_ucl.max_users or 1000 + + rspamd_config:add_on_load(function(_, ev_base, _) + + rspamd_config:add_periodic(ev_base, 0.0, function(cfg, _) + + local function stat_redis_cb(err, data) + -- TODO: write this function + + end + + lua_redis.exec_redis_script(stat_script_id, + { ev_base = ev_base, cfg = cfg, is_write = false }, + stat_redis_cb, { symbol, max_users }) + return 30.0 -- TODO: make configurable + end) + end) return gen_classify_functor(redis_params, classify_script_id), gen_learn_functor(redis_params, learn_script_id) end |