]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Extend redis lock when learning spawned
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 6 Dec 2016 12:34:38 +0000 (12:34 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 6 Dec 2016 12:35:04 +0000 (12:35 +0000)
src/plugins/lua/fann_redis.lua

index 18d91314fa489028a39f970f2d401800117d10bc..468e9b4669d54d5b3176407590bd4cff4f066757 100644 (file)
@@ -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)