From: Vsevolod Stakhov Date: Tue, 6 Dec 2016 12:34:38 +0000 (+0000) Subject: [Feature] Extend redis lock when learning spawned X-Git-Tag: 1.4.2~4^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=635b2e4a22a0f9fd2f81256010e8230ebde904ed;p=thirdparty%2Frspamd.git [Feature] Extend redis lock when learning spawned --- diff --git a/src/plugins/lua/fann_redis.lua b/src/plugins/lua/fann_redis.lua index 18d91314fa..468e9b4669 100644 --- a/src/plugins/lua/fann_redis.lua +++ b/src/plugins/lua/fann_redis.lua @@ -591,6 +591,34 @@ local function train_fann(_, ev_base, elt) 'LRANGE', -- command {fann_prefix .. elt .. '_spam', '0', '-1'} ) + + rspamd_config:add_periodic(ev_base, 30.0, + function(_, _) + local function redis_lock_extend_cb(_err, _) + if _err then + rspamd_logger.errx(rspamd_config, 'cannot lock ANN %s from redis: %s', + fann_prefix .. elt, _err) + else + rspamd_logger.infox(rspamd_config, 'extend lock for ANN %s for 30 seconds', + fann_prefix .. elt) + end + end + if learning_spawned then + redis_make_request(ev_base, + rspamd_config, + nil, + true, -- is write + redis_lock_extend_cb, --callback + 'INCRBY', -- command + {fann_prefix .. elt, '30'} + ) + else + return false -- do not plan any more updates + end + + return true + end + ) rspamd_logger.infox(rspamd_config, 'lock ANN %s for learning', elt) else rspamd_logger.infox(rspamd_config, 'do not learn ANN %s, locked by another process', elt)