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.5.0~661 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5d8adf3adc41829252862009c18b5cbda21928aa;p=rspamd.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 18d91314f..468e9b466 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)