FIX: when a class changes family avoid feedback loops

FIX: when a class changes family avoid feedback loops

Schedules are either per host or global, if a user changes one from one family to the other there was a bad case where we would keep on attempting to schedule a global job (when global was changed to per host)

This adds protection to remove incorrect family schedules.

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5da0e8a..11e03f6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+# 0.12.1 - 30-08-2019
+
+- Jobs that change family from per host to non per host can cause a tight loop
+
 # 0.12.0 - 29-08-2019
 
 - Add support for multiple workers which allows avoiding queue starvation
diff --git a/lib/mini_scheduler/manager.rb b/lib/mini_scheduler/manager.rb
index 3caffbf..6a05728 100644
--- a/lib/mini_scheduler/manager.rb
+++ b/lib/mini_scheduler/manager.rb
@@ -265,11 +265,14 @@ module MiniScheduler
 
       if due.to_i <= Time.now.to_i
         klass = get_klass(key)
-        unless klass
+        if !klass || (
+          (klass.is_per_host && !hostname) || (hostname && !klass.is_per_host)
+        )
           # corrupt key, nuke it (renamed job or something)
           redis.zrem Manager.queue_key(queue, hostname), key
           return
         end
+
         info = schedule_info(klass)
         info.prev_run = Time.now.to_i
         info.prev_result = "QUEUED"
diff --git a/lib/mini_scheduler/version.rb b/lib/mini_scheduler/version.rb
index ebc3f7a..3d023bc 100644
--- a/lib/mini_scheduler/version.rb
+++ b/lib/mini_scheduler/version.rb
@@ -1,5 +1,5 @@
 # frozen_string_literal: true
 
 module MiniScheduler
-  VERSION = "0.12.0"
+  VERSION = "0.12.1"
 end

GitHub sha: 41c0fc02

1 Like