1+ # frozen_string_literal: true
2+
13require 'sidekiq'
24require 'sidekiq/web'
35
1012require 'sidekiq_adhoc_job/web'
1113
1214module SidekiqAdhocJob
13-
1415 StringUtil ||= Utils ::String
1516
1617 module Strategies
@@ -29,10 +30,20 @@ def self.config
2930 end
3031
3132 def self . init
32- SidekiqAdhocJob ::WorkerClassesLoader . load ( @_config . module_names , load_paths : @_config . load_paths , strategy : @_config . strategy )
33+ SidekiqAdhocJob ::WorkerClassesLoader . load ( @_config . module_names , load_paths : @_config . load_paths ,
34+ strategy : @_config . strategy )
35+
36+ # Check if we're using Sidekiq 8+ which requires the new API
37+ if Gem ::Version . new ( Sidekiq ::VERSION ) >= Gem ::Version . new ( '8.0.0' )
38+ Sidekiq ::Web . configure do |config |
39+ config . register_extension ( SidekiqAdhocJob ::Web , name : 'Adhoc Jobs' , tab : 'adhoc_jobs' , index : 'adhoc-jobs' )
40+ end
41+ else
42+ # Legacy API for Sidekiq 7.x
43+ Sidekiq ::Web . register ( SidekiqAdhocJob ::Web )
44+ Sidekiq ::Web . tabs [ 'adhoc_jobs' ] = 'adhoc-jobs'
45+ end
3346
34- Sidekiq ::Web . register ( SidekiqAdhocJob ::Web )
35- Sidekiq ::Web . tabs [ 'adhoc_jobs' ] = 'adhoc-jobs'
3647 Sidekiq ::Web . locales << File . expand_path ( 'sidekiq_adhoc_job/web/locales' , __dir__ )
3748
3849 assets_path = File . expand_path ( 'sidekiq_adhoc_job/web/assets' , __dir__ )
@@ -41,11 +52,10 @@ def self.init
4152 root : assets_path ,
4253 cascade : true ,
4354 header_rules : [ [ :all , { 'cache-control' => 'private, max-age=86400' } ] ]
44-
45- end
55+ end
4656
4757 def self . strategies
48- @_strategies ||= [ ]
58+ @strategies ||= [ ]
4959 end
5060
5161 class Configuration
@@ -94,10 +104,10 @@ def strategy
94104 SidekiqAdhocJob ::Strategies ::Default . new ( module_names )
95105 else
96106 strategy_klass = SidekiqAdhocJob ::Strategies . const_get ( StringUtil . camelize ( strategy_name . to_s ) . to_s )
97- raise InvalidConfigurationError , "Invalid strategy name" unless strategy_klass
107+ raise InvalidConfigurationError , 'Invalid strategy name' unless strategy_klass
108+
98109 strategy_klass . new ( module_names )
99110 end
100111 end
101112 end
102-
103113end
0 commit comments