Class: SidekiqScheduler::SidekiqAdapter
- Inherits:
-
Object
- Object
- SidekiqScheduler::SidekiqAdapter
- Defined in:
- lib/sidekiq-scheduler/sidekiq_adapter.rb
Constant Summary collapse
- SIDEKIQ_GTE_6_5_0 =
Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('6.5.0')
- SIDEKIQ_GTE_7_0_0 =
Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('7.0.0')
Class Method Summary collapse
- .check_using_old_sidekiq_scheduler_config!(sidekiq_config) ⇒ Object
- .fetch_scheduler_config_from_sidekiq(sidekiq_config) ⇒ Object
- .redis_key_exists?(key_name) ⇒ Boolean
- .sidekiq_queues(sidekiq_config) ⇒ Object
- .start_schedule_manager(sidekiq_config:, schedule_manager:) ⇒ Object
- .stop_schedule_manager(sidekiq_config:) ⇒ Object
Class Method Details
.check_using_old_sidekiq_scheduler_config!(sidekiq_config) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sidekiq-scheduler/sidekiq_adapter.rb', line 20 def self.check_using_old_sidekiq_scheduler_config!(sidekiq_config) %i[enabled dynamic dynamic_every schedule listened_queues_only rufus_scheduler_options].each do |option| if SIDEKIQ_GTE_7_0_0 if sidekiq_config.key?(option) raise OptionNotSupportedAnymore, ":#{option} option should be under the :scheduler: key" end elsif SIDEKIQ_GTE_6_5_0 unless sidekiq_config[option].nil? raise OptionNotSupportedAnymore, ":#{option} option should be under the :scheduler: key" end else if sidekiq_config..key?(option) raise OptionNotSupportedAnymore, ":#{option} option should be under the :scheduler: key" end end end end |
.fetch_scheduler_config_from_sidekiq(sidekiq_config) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sidekiq-scheduler/sidekiq_adapter.rb', line 8 def self.fetch_scheduler_config_from_sidekiq(sidekiq_config) return {} if sidekiq_config.nil? check_using_old_sidekiq_scheduler_config!(sidekiq_config) if SIDEKIQ_GTE_6_5_0 sidekiq_config.fetch(:scheduler, {}) else sidekiq_config..fetch(:scheduler, {}) end end |
.redis_key_exists?(key_name) ⇒ Boolean
70 71 72 73 74 75 76 77 78 |
# File 'lib/sidekiq-scheduler/sidekiq_adapter.rb', line 70 def self.redis_key_exists?(key_name) Sidekiq.redis do |r| if SIDEKIQ_GTE_7_0_0 r.exists(key_name) > 0 else r.exists?(key_name) end end end |
.sidekiq_queues(sidekiq_config) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sidekiq-scheduler/sidekiq_adapter.rb', line 56 def self.sidekiq_queues(sidekiq_config) if SIDEKIQ_GTE_7_0_0 if sidekiq_config.nil? || (sidekiq_config.respond_to?(:empty?) && sidekiq_config.empty?) Sidekiq.instance_variable_get(:@config).queues.map(&:to_s) else sidekiq_config.queues.map(&:to_s) end elsif SIDEKIQ_GTE_6_5_0 Sidekiq[:queues].map(&:to_s) else Sidekiq.[:queues].map(&:to_s) end end |
.start_schedule_manager(sidekiq_config:, schedule_manager:) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/sidekiq-scheduler/sidekiq_adapter.rb', line 38 def self.start_schedule_manager(sidekiq_config:, schedule_manager:) if SIDEKIQ_GTE_6_5_0 sidekiq_config[:schedule_manager] = schedule_manager sidekiq_config[:schedule_manager].start else sidekiq_config.[:schedule_manager] = schedule_manager sidekiq_config.[:schedule_manager].start end end |
.stop_schedule_manager(sidekiq_config:) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/sidekiq-scheduler/sidekiq_adapter.rb', line 48 def self.stop_schedule_manager(sidekiq_config:) if SIDEKIQ_GTE_6_5_0 sidekiq_config[:schedule_manager].stop else sidekiq_config.[:schedule_manager].stop end end |