DEV: add frozen string literal

DEV: add frozen string literal

plus some minor cleanup on distributed mutex

diff --git a/app/models/mini_scheduler/stat.rb b/app/models/mini_scheduler/stat.rb
index f47e07e..1910109 100644
--- a/app/models/mini_scheduler/stat.rb
+++ b/app/models/mini_scheduler/stat.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 if defined?(ActiveRecord::Base)
   module MiniScheduler
     class Stat < ActiveRecord::Base
diff --git a/lib/generators/mini_scheduler/install/install_generator.rb b/lib/generators/mini_scheduler/install/install_generator.rb
index 3e825a5..859df43 100644
--- a/lib/generators/mini_scheduler/install/install_generator.rb
+++ b/lib/generators/mini_scheduler/install/install_generator.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'rails/generators'
 require 'rails/generators/migration'
 require 'active_record'
diff --git a/lib/generators/mini_scheduler/install/templates/create_mini_scheduler_stats.rb b/lib/generators/mini_scheduler/install/templates/create_mini_scheduler_stats.rb
index 37211cc..5839674 100644
--- a/lib/generators/mini_scheduler/install/templates/create_mini_scheduler_stats.rb
+++ b/lib/generators/mini_scheduler/install/templates/create_mini_scheduler_stats.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class CreateMiniSchedulerStats < ActiveRecord::Migration[4.2]
   def change
     create_table :scheduler_stats do |t|
diff --git a/lib/generators/mini_scheduler/install/templates/mini_scheduler_initializer.rb b/lib/generators/mini_scheduler/install/templates/mini_scheduler_initializer.rb
index 09ea03f..f68dc05 100644
--- a/lib/generators/mini_scheduler/install/templates/mini_scheduler_initializer.rb
+++ b/lib/generators/mini_scheduler/install/templates/mini_scheduler_initializer.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 MiniScheduler.configure do |config|
   # An instance of Redis. See https://github.com/redis/redis-rb
 
diff --git a/lib/mini_scheduler.rb b/lib/mini_scheduler.rb
index bbb124b..8eb5228 100644
--- a/lib/mini_scheduler.rb
+++ b/lib/mini_scheduler.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
 require "mini_scheduler/engine"
 require 'mini_scheduler/schedule'
 require 'mini_scheduler/schedule_info'
diff --git a/lib/mini_scheduler/distributed_mutex.rb b/lib/mini_scheduler/distributed_mutex.rb
index a37f905..d2c1961 100644
--- a/lib/mini_scheduler/distributed_mutex.rb
+++ b/lib/mini_scheduler/distributed_mutex.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 module MiniScheduler
   class DistributedMutex
     class Timeout < StandardError; end
@@ -30,13 +32,11 @@ module MiniScheduler
       attempts = 0
       sleep_duration = BASE_SLEEP_DURATION
       while !try_to_get_lock
-        sleep sleep_duration
 
-        # Exponential backoff
-        if sleep_duration >= MAX_SLEEP_DURATION
-          sleep_duration = MAX_SLEEP_DURATION
-        else
-          sleep_duration = sleep_duration * 2
+        sleep(sleep_duration)
+
+        if sleep_duration < MAX_SLEEP_DURATION
+          sleep_duration = [sleep_duration * 2, MAX_SLEEP_DURATION].min
         end
 
         attempts += 1
diff --git a/lib/mini_scheduler/engine.rb b/lib/mini_scheduler/engine.rb
index b64c4ec..108ff16 100644
--- a/lib/mini_scheduler/engine.rb
+++ b/lib/mini_scheduler/engine.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 if defined?(::Rails)
   module MiniScheduler
     class Engine < ::Rails::Engine
diff --git a/lib/mini_scheduler/manager.rb b/lib/mini_scheduler/manager.rb
index db173f9..d84f654 100644
--- a/lib/mini_scheduler/manager.rb
+++ b/lib/mini_scheduler/manager.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 module MiniScheduler
   class Manager
     attr_accessor :random_ratio, :redis, :enable_stats, :queue
diff --git a/lib/mini_scheduler/schedule.rb b/lib/mini_scheduler/schedule.rb
index 87a25a6..cf5e3f5 100644
--- a/lib/mini_scheduler/schedule.rb
+++ b/lib/mini_scheduler/schedule.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 module MiniScheduler::Schedule
 
   def queue(value = nil)
diff --git a/lib/mini_scheduler/schedule_info.rb b/lib/mini_scheduler/schedule_info.rb
index c72552e..7c5c392 100644
--- a/lib/mini_scheduler/schedule_info.rb
+++ b/lib/mini_scheduler/schedule_info.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 module MiniScheduler
   class ScheduleInfo
     attr_accessor :next_run,
diff --git a/lib/mini_scheduler/version.rb b/lib/mini_scheduler/version.rb
index 7c981b7..eb5fde2 100644
--- a/lib/mini_scheduler/version.rb
+++ b/lib/mini_scheduler/version.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 module MiniScheduler
   VERSION = "0.10.0"
 end
diff --git a/lib/mini_scheduler/web.rb b/lib/mini_scheduler/web.rb
index 67c4e4b..c755250 100644
--- a/lib/mini_scheduler/web.rb
+++ b/lib/mini_scheduler/web.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
 # Based off sidetiq https://github.com/tobiassvn/sidetiq/blob/master/lib/sidetiq/web.rb
 module MiniScheduler
   module Web
diff --git a/spec/mini_scheduler/manager_spec.rb b/spec/mini_scheduler/manager_spec.rb
index 12be603..116eaa5 100644
--- a/spec/mini_scheduler/manager_spec.rb
+++ b/spec/mini_scheduler/manager_spec.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
 # encoding: utf-8
 
 describe MiniScheduler::Manager do
diff --git a/spec/mini_scheduler/schedule_info_spec.rb b/spec/mini_scheduler/schedule_info_spec.rb
index 5ef53c8..bc27bb1 100644
--- a/spec/mini_scheduler/schedule_info_spec.rb
+++ b/spec/mini_scheduler/schedule_info_spec.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
 # encoding: utf-8
 
 describe MiniScheduler::ScheduleInfo do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 0f9c587..b897fb8 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require 'mock_redis'
 require 'mini_scheduler'
 require 'active_support/core_ext/numeric/time'

GitHub sha: 5346f5e2

1 Like