sidekiq-scheduler 4.0.3 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c16869144651f4193112eb896e092d382af94340b373f11ba92cefbdcc8fa875
4
- data.tar.gz: 00b8efaca9cfcfe0379b633f5ca8aa215fa1f382fcd86fd29910b7ac64e6db7f
3
+ metadata.gz: ff0427944d5e42f269323d2178f99e85883f0bf1c319606e492fd3c2f248cebc
4
+ data.tar.gz: 2589826435a6609724de6adae9c2376195cf2336907a30f836067aebb3d00b70
5
5
  SHA512:
6
- metadata.gz: 5afc74e4fa2a54d2b00e9d1a1343f64f242d217bee9c0ec170a4fd502cc7d7233598123c769034b7ad830c75eecab1f9aa99513bcac0d42bcaef91d771ddf7d0
7
- data.tar.gz: 2e096c861063f78ce359807fd6e58477ca3e8489d645dca3a5c188e5713ed07b61392ddc96ec0d0eb6f5c0c6b3da91aec3c9cf3e27dcd9f4094f37b3185352b1
6
+ metadata.gz: 342671556514ae49da4d84b4a6e2e014060d69b7149284ce079bf56dedbf51d5c6e6e31987606e05e62d9d1070c47ff15e464dba10b69b1bf0292811c43292d8
7
+ data.tar.gz: b81d626a69832dec123de5fde3d255d1f4c4f3158a7298d26c10746b4e5444bdabc74f6f47e6da2823fc0786e9cb136e9ed59c41555674d1b5ede8e075194d4f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ # 5.0.1
2
+
3
+ - [**ENHANCEMENT**] Adds Ruby 3.2 to the CI matrix. [#420](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/420)
4
+ - [**DOCS**] README: refer to v5 as released. [#421](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/421)
5
+ - [**FIX**] Fix dependency on Rails `.present?` method. [#425](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/425)
6
+
7
+ # 5.0.0
8
+
9
+ - [**FIX**] Ensure generated scheduled time has a precision of 3 miliseconds. [#418](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/418)
10
+
11
+ *Note 1:* Check [# 5.0.0.beta1](#500beta1) & [# 5.0.0.beta2](#500beta2) releases for breaking changes.
12
+
13
+ *Note 2:* Sidekiq Embedding is yet not supported, see [#419](https://github.com/sidekiq-scheduler/sidekiq-scheduler/issues/419) for more details.
14
+
15
+
16
+ # 5.0.0.beta2
17
+
18
+ - [**FIX**] Drop explicit redis dependency [#416](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/416)
19
+
20
+ # 5.0.0.beta1
21
+
22
+ - [**BREAKING CHANGE**] Moves all sidekiq-scheduler config options under the `scheduler` key in the `sidekiq.yml` file [#412](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/412)
23
+ - If you're migrating from v4 to v5, any `sidekiq-scheduler` config you may have in your `sidekiq.yml` should be moved under the `scheduler` key.
24
+ - See [#412](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/412) to see which are the config options that you need to move under the `scheduler` key.
25
+
26
+ - [**BREAKING CHANGE**] Drop support for EOL Ruby & Sidekiq versions (Ruby: `2.5.x` & `2.6.x`; Sidekiq: `4.x` & `5.x`) [#411](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/411)
27
+
28
+ - [**FIX**] Add support for Sidekiq 7 [#410](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/410)
29
+
30
+
1
31
  # 4.0.3
2
32
 
3
33
  - [**GH Actions**] Add dependabot for GitHub Actions [#390](https://github.com/sidekiq-scheduler/sidekiq-scheduler/pull/390)
data/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
  `sidekiq-scheduler` is an extension to [Sidekiq](http://github.com/mperham/sidekiq) that
19
19
  pushes jobs in a scheduled way, mimicking cron utility.
20
20
 
21
- __Note:__ Current branch contains work of the v4 release, if you are looking for version 2.2.* or 3.*, go to [2.2-stable branch](https://github.com/sidekiq-scheduler/sidekiq-scheduler/tree/2.2-stable) / [v3-stable](https://github.com/sidekiq-scheduler/sidekiq-scheduler/tree/v3-stable).
21
+ __Note:__ Current branch contains work of the v5 release, if you are looking for version 2.2.\*, 3.\*, or 4.\*, go to [2.2-stable branch](https://github.com/sidekiq-scheduler/sidekiq-scheduler/tree/2.2-stable) / [v3-stable](https://github.com/sidekiq-scheduler/sidekiq-scheduler/tree/v3-stable) / [v4-stable](https://github.com/sidekiq-scheduler/sidekiq-scheduler/tree/v4-stable).
22
22
 
23
23
  ## Installation
24
24
 
@@ -48,10 +48,11 @@ end
48
48
  ``` yaml
49
49
  # config/sidekiq.yml
50
50
 
51
- :schedule:
52
- hello_world:
53
- cron: '0 * * * * *' # Runs once per minute
54
- class: HelloWorld
51
+ :scheduler:
52
+ :schedule:
53
+ hello_world:
54
+ cron: '0 * * * * *' # Runs once per minute
55
+ class: HelloWorld
55
56
  ```
56
57
 
57
58
  Run sidekiq:
@@ -83,40 +84,41 @@ Configuration options are placed inside `sidekiq.yml` config file.
83
84
  Available options are:
84
85
 
85
86
  ``` yaml
86
- :dynamic: <if true the schedule can be modified in runtime [false by default]>
87
- :dynamic_every: <if dynamic is true, the schedule is reloaded every interval [5s by default]>
88
- :enabled: <enables scheduler if true [true by default]>
89
87
  :scheduler:
88
+ :dynamic: <if true the schedule can be modified in runtime [false by default]>
89
+ :dynamic_every: <if dynamic is true, the schedule is reloaded every interval [5s by default]>
90
+ :enabled: <enables scheduler if true [true by default]>
90
91
  :listened_queues_only: <push jobs whose queue is being listened by sidekiq [false by default]>
91
- :rufus_scheduler_options: <Set custom options for rufus scheduler, like max_work_threads [{} by default]>
92
+ :rufus_scheduler_options: <Set custom options for rufus scheduler, like max_work_threads [{} by default]>
92
93
  ```
93
94
 
94
95
  ## Schedule configuration
95
96
 
96
- The schedule is configured through the `:schedule` config entry in the sidekiq config file:
97
+ The schedule is configured through the `:scheduler:` -> `:schedule` config entry in the sidekiq config file:
97
98
 
98
99
  ``` yaml
99
- :schedule:
100
- CancelAbandonedOrders:
101
- cron: '0 */5 * * * *' # Runs when second = 0, every 5 minutes
100
+ :scheduler:
101
+ :schedule:
102
+ CancelAbandonedOrders:
103
+ cron: '0 */5 * * * *' # Runs when second = 0, every 5 minutes
102
104
 
103
- queue_documents_for_indexing:
104
- cron: '0 0 * * * *' # Runs every hour
105
+ queue_documents_for_indexing:
106
+ cron: '0 0 * * * *' # Runs every hour
105
107
 
106
- # By default the job name will be taken as worker class name.
107
- # If you want to have a different job name and class name, provide the 'class' option
108
- class: QueueDocuments
108
+ # By default the job name will be taken as worker class name.
109
+ # If you want to have a different job name and class name, provide the 'class' option
110
+ class: QueueDocuments
109
111
 
110
- queue: slow
111
- args: ['*.pdf']
112
- description: "This job queues pdf content for indexing in solr"
112
+ queue: slow
113
+ args: ['*.pdf']
114
+ description: "This job queues pdf content for indexing in solr"
113
115
 
114
- # Enable the `metadata` argument which will pass a Hash containing the schedule metadata
115
- # as the last argument of the `perform` method. `false` by default.
116
- include_metadata: true
116
+ # Enable the `metadata` argument which will pass a Hash containing the schedule metadata
117
+ # as the last argument of the `perform` method. `false` by default.
118
+ include_metadata: true
117
119
 
118
- # Enable / disable a job. All jobs are enabled by default.
119
- enabled: true
120
+ # Enable / disable a job. All jobs are enabled by default.
121
+ enabled: true
120
122
  ```
121
123
 
122
124
  ### Schedule metadata
@@ -157,9 +159,10 @@ Cron, every, and interval types push jobs into sidekiq in a recurrent manner.
157
159
  `cron` follows the same pattern as cron utility, with seconds resolution.
158
160
 
159
161
  ``` yaml
160
- :schedule:
161
- HelloWorld:
162
- cron: '0 * * * * *' # Runs when second = 0
162
+ :scheduler:
163
+ :schedule:
164
+ HelloWorld:
165
+ cron: '0 * * * * *' # Runs when second = 0
163
166
  ```
164
167
 
165
168
  `every` triggers following a given frequency:
@@ -250,7 +253,8 @@ When `:dynamic` flag is set to `true`, schedule changes are loaded every 5 secon
250
253
 
251
254
  ``` yaml
252
255
  # config/sidekiq.yml
253
- :dynamic: true
256
+ :scheduler:
257
+ :dynamic: true
254
258
  ```
255
259
 
256
260
  If `:dynamic` flag is set to `false`, you'll have to reload the schedule manually in sidekiq
@@ -299,8 +303,9 @@ You can also override the thread pool size in Rufus Scheduler by setting the fol
299
303
  ---
300
304
  ...
301
305
 
302
- rufus_scheduler_options:
303
- max_work_threads: 5
306
+ :scheduler:
307
+ rufus_scheduler_options:
308
+ max_work_threads: 5
304
309
 
305
310
  ...
306
311
  ```
@@ -386,12 +391,13 @@ Say you have one process with the schedule:
386
391
 
387
392
  :queues:
388
393
  - default
389
- :schedule:
390
- do_something_every_minute:
391
- class: DoSomethingJob
392
- args: matey
393
- queue: :scheduler
394
- cron: '0 * * * * * America/Los_Angeles'
394
+ :scheduler:
395
+ :schedule:
396
+ do_something_every_minute:
397
+ class: DoSomethingJob
398
+ args: matey
399
+ queue: :scheduler
400
+ cron: '0 * * * * * America/Los_Angeles'
395
401
  ```
396
402
 
397
403
  And a separate separate configured process without one:
@@ -401,7 +407,8 @@ And a separate separate configured process without one:
401
407
  - scheduler
402
408
 
403
409
  ## NOTE Disable the Scheduler
404
- :enabled: false
410
+ :scheduler:
411
+ :enabled: false
405
412
  ```
406
413
 
407
414
  ### Details
@@ -0,0 +1,80 @@
1
+ module SidekiqScheduler
2
+ class Config
3
+ # We have to set the default as nil because the scheduler could be instantiated without
4
+ # passing the sidekiq config, and in those scenarios we don't want to fail
5
+ def initialize(sidekiq_config: nil, without_defaults: false)
6
+ @sidekiq_config = sidekiq_config
7
+ @scheduler_config = fetch_scheduler_config(sidekiq_config, without_defaults)
8
+ end
9
+
10
+ def enabled?
11
+ scheduler_config[:enabled]
12
+ end
13
+
14
+ def enabled=(value)
15
+ scheduler_config[:enabled] = value
16
+ end
17
+
18
+ def dynamic?
19
+ scheduler_config[:dynamic]
20
+ end
21
+
22
+ def dynamic=(value)
23
+ scheduler_config[:dynamic] = value
24
+ end
25
+
26
+ def dynamic_every?
27
+ scheduler_config[:dynamic_every]
28
+ end
29
+
30
+ def dynamic_every=(value)
31
+ scheduler_config[:dynamic_every] = value
32
+ end
33
+
34
+ def schedule
35
+ scheduler_config[:schedule]
36
+ end
37
+
38
+ def schedule=(value)
39
+ scheduler_config[:schedule] = value
40
+ end
41
+
42
+ def listened_queues_only?
43
+ scheduler_config[:listened_queues_only]
44
+ end
45
+
46
+ def listened_queues_only=(value)
47
+ scheduler_config[:listened_queues_only] = value
48
+ end
49
+
50
+ def rufus_scheduler_options
51
+ scheduler_config[:rufus_scheduler_options]
52
+ end
53
+
54
+ def rufus_scheduler_options=(value)
55
+ scheduler_config[:rufus_scheduler_options] = value
56
+ end
57
+
58
+ def sidekiq_queues
59
+ SidekiqScheduler::SidekiqAdapter.sidekiq_queues(sidekiq_config)
60
+ end
61
+
62
+ private
63
+
64
+ attr_reader :scheduler_config
65
+ attr_reader :sidekiq_config
66
+
67
+ DEFAULT_OPTIONS = {
68
+ enabled: true,
69
+ dynamic: false,
70
+ dynamic_every: '5s',
71
+ schedule: {},
72
+ rufus_scheduler_options: {}
73
+ }.freeze
74
+
75
+ def fetch_scheduler_config(sidekiq_config, without_defaults)
76
+ conf = SidekiqScheduler::SidekiqAdapter.fetch_scheduler_config_from_sidekiq(sidekiq_config)
77
+ without_defaults ? conf : DEFAULT_OPTIONS.merge(conf)
78
+ end
79
+ end
80
+ end
@@ -1,5 +1,3 @@
1
- require 'redis'
2
-
3
1
  require 'sidekiq-scheduler/schedule'
4
2
  require 'sidekiq-scheduler/scheduler'
5
3
 
@@ -10,19 +8,12 @@ module SidekiqScheduler
10
8
  # from Redis onto the work queues
11
9
  #
12
10
  class Manager
13
- DEFAULT_SCHEDULER_OPTIONS = {
14
- enabled: true,
15
- dynamic: false,
16
- dynamic_every: '5s',
17
- schedule: {}
18
- }
19
-
20
- def initialize(options)
21
- scheduler_options = load_scheduler_options(options)
11
+ def initialize(config)
12
+ set_current_scheduler_options(config)
22
13
 
23
- @scheduler_instance = SidekiqScheduler::Scheduler.new(scheduler_options)
14
+ @scheduler_instance = SidekiqScheduler::Scheduler.new(config)
24
15
  SidekiqScheduler::Scheduler.instance = @scheduler_instance
25
- Sidekiq.schedule = scheduler_options[:schedule] if @scheduler_instance.enabled
16
+ Sidekiq.schedule = config.schedule if @scheduler_instance.enabled
26
17
  end
27
18
 
28
19
  def stop
@@ -35,19 +26,19 @@ module SidekiqScheduler
35
26
 
36
27
  private
37
28
 
38
- def load_scheduler_options(options)
39
- options[:listened_queues_only] = options.fetch(:scheduler, {})[:listened_queues_only]
40
- scheduler_options = DEFAULT_SCHEDULER_OPTIONS.merge(options)
41
-
42
- current_options = {
43
- enabled: SidekiqScheduler::Scheduler.enabled,
44
- dynamic: SidekiqScheduler::Scheduler.dynamic,
45
- dynamic_every: SidekiqScheduler::Scheduler.dynamic_every,
46
- schedule: Sidekiq.schedule,
47
- listened_queues_only: SidekiqScheduler::Scheduler.listened_queues_only
48
- }.delete_if { |_, value| value.nil? }
49
-
50
- scheduler_options.merge(current_options)
29
+ def set_current_scheduler_options(config)
30
+ enabled = SidekiqScheduler::Scheduler.enabled
31
+ dynamic = SidekiqScheduler::Scheduler.dynamic
32
+ dynamic_every = SidekiqScheduler::Scheduler.dynamic_every
33
+ listened_queues_only = SidekiqScheduler::Scheduler.listened_queues_only
34
+
35
+ config.enabled = enabled unless enabled.nil?
36
+ config.dynamic = dynamic unless dynamic.nil?
37
+ config.dynamic_every = dynamic_every unless dynamic_every.nil?
38
+ unless Sidekiq.schedule.nil? || (Sidekiq.schedule.respond_to?(:empty?) && Sidekiq.schedule.empty?)
39
+ config.schedule = Sidekiq.schedule
40
+ end
41
+ config.listened_queues_only = listened_queues_only unless listened_queues_only.nil?
51
42
  end
52
43
  end
53
44
  end
@@ -96,7 +96,7 @@ module SidekiqScheduler
96
96
  #
97
97
  # @return [Boolean] true if the schedules key is set, false otherwise
98
98
  def self.schedule_exist?
99
- Sidekiq.redis { |r| r.exists?(schedules_key) }
99
+ SidekiqScheduler::SidekiqAdapter.redis_key_exists?(schedules_key)
100
100
  end
101
101
 
102
102
  # Returns all the schedule changes for a given time range.
@@ -136,7 +136,7 @@ module SidekiqScheduler
136
136
  end
137
137
  end
138
138
 
139
- registered
139
+ registered.instance_of?(Integer) ? (registered > 0) : registered
140
140
  end
141
141
 
142
142
  # Removes instances of the job older than 24 hours
@@ -210,7 +210,7 @@ module SidekiqScheduler
210
210
  end
211
211
 
212
212
  private
213
-
213
+
214
214
  # Returns the value of a Redis stored hash field
215
215
  #
216
216
  # @param [String] hash_key The key name of the hash
@@ -2,6 +2,7 @@ require 'rufus/scheduler'
2
2
  require 'json'
3
3
  require 'sidekiq-scheduler/rufus_utils'
4
4
  require 'sidekiq-scheduler/redis_manager'
5
+ require 'sidekiq-scheduler/config'
5
6
 
6
7
  module SidekiqScheduler
7
8
  class Scheduler
@@ -10,6 +11,15 @@ module SidekiqScheduler
10
11
  alias_method :params, :opts
11
12
  end
12
13
 
14
+ # TODO: Can we remove those attr_accessor's? If we need to keep them, we should
15
+ # update those values on the config object instead of just here in the scheduler.
16
+ # That's why we need to do what we do in the set_current_scheduler_options (not
17
+ # saying we will have to do it somehow still)
18
+ #
19
+ # NOTE: ^ Keeping this TODO here for now, in a future version of this project
20
+ # we will remove those attr acessors and use only our config object. For now,
21
+ # let's keep as it is.
22
+
13
23
  # Set to enable or disable the scheduler.
14
24
  attr_accessor :enabled
15
25
 
@@ -41,12 +51,14 @@ module SidekiqScheduler
41
51
  end
42
52
  end
43
53
 
44
- def initialize(options = {})
45
- self.enabled = options[:enabled]
46
- self.dynamic = options[:dynamic]
47
- self.dynamic_every = options[:dynamic_every]
48
- self.listened_queues_only = options[:listened_queues_only]
49
- self.rufus_scheduler_options = options[:rufus_scheduler_options] || {}
54
+ def initialize(config = SidekiqScheduler::Config.new(without_defaults: true))
55
+ @scheduler_config = config
56
+
57
+ self.enabled = config.enabled?
58
+ self.dynamic = config.dynamic?
59
+ self.dynamic_every = config.dynamic_every?
60
+ self.listened_queues_only = config.listened_queues_only?
61
+ self.rufus_scheduler_options = config.rufus_scheduler_options
50
62
  end
51
63
 
52
64
  # the Rufus::Scheduler jobs that are scheduled
@@ -82,7 +94,7 @@ module SidekiqScheduler
82
94
  Sidekiq.logger.info 'Schedule empty! Set Sidekiq.schedule' if Sidekiq.schedule.empty?
83
95
 
84
96
  @scheduled_jobs = {}
85
- queues = sidekiq_queues
97
+ queues = scheduler_config.sidekiq_queues
86
98
 
87
99
  Sidekiq.schedule.each do |name, config|
88
100
  if !listened_queues_only || enabled_queue?(config['queue'].to_s, queues)
@@ -158,7 +170,7 @@ module SidekiqScheduler
158
170
  config = prepare_arguments(job_config.dup)
159
171
 
160
172
  if config.delete('include_metadata')
161
- config['args'] = arguments_with_metadata(config['args'], "scheduled_at" => time.to_f)
173
+ config['args'] = arguments_with_metadata(config['args'], "scheduled_at" => time.to_f.round(3))
162
174
  end
163
175
 
164
176
  if SidekiqScheduler::Utils.active_job_enqueue?(config['class'])
@@ -238,6 +250,8 @@ module SidekiqScheduler
238
250
 
239
251
  private
240
252
 
253
+ attr_reader :scheduler_config
254
+
241
255
  def new_job(name, interval_type, config, schedule, options)
242
256
  options = options.merge({ :job => true, :tags => [name] })
243
257
 
@@ -277,7 +291,7 @@ module SidekiqScheduler
277
291
  # since epoch.
278
292
  #
279
293
  # @example with hash argument
280
- # arguments_with_metadata({value: 1}, scheduled_at: Time.now)
294
+ # arguments_with_metadata({value: 1}, scheduled_at: Time.now.round(3))
281
295
  # #=> [{value: 1}, {scheduled_at: <miliseconds since epoch>}]
282
296
  #
283
297
  # @param args [Array|Hash]
@@ -291,14 +305,6 @@ module SidekiqScheduler
291
305
  end
292
306
  end
293
307
 
294
- def sidekiq_queues
295
- if SIDEKIQ_GTE_6_5_0
296
- Sidekiq[:queues].map(&:to_s)
297
- else
298
- Sidekiq.options[:queues].map(&:to_s)
299
- end
300
- end
301
-
302
308
  # Returns true if a job's queue is included in the array of queues
303
309
  #
304
310
  # If queues are empty, returns true.
@@ -0,0 +1,80 @@
1
+ module SidekiqScheduler
2
+ class OptionNotSupportedAnymore < StandardError; end
3
+
4
+ class SidekiqAdapter
5
+ SIDEKIQ_GTE_6_5_0 = Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('6.5.0')
6
+ SIDEKIQ_GTE_7_0_0 = Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('7.0.0')
7
+
8
+ def self.fetch_scheduler_config_from_sidekiq(sidekiq_config)
9
+ return {} if sidekiq_config.nil?
10
+
11
+ check_using_old_sidekiq_scheduler_config!(sidekiq_config)
12
+
13
+ if SIDEKIQ_GTE_6_5_0
14
+ sidekiq_config.fetch(:scheduler, {})
15
+ else
16
+ sidekiq_config.options.fetch(:scheduler, {})
17
+ end
18
+ end
19
+
20
+ def self.check_using_old_sidekiq_scheduler_config!(sidekiq_config)
21
+ %i[enabled dynamic dynamic_every schedule listened_queues_only rufus_scheduler_options].each do |option|
22
+ if SIDEKIQ_GTE_7_0_0
23
+ if sidekiq_config.key?(option)
24
+ raise OptionNotSupportedAnymore, ":#{option} option should be under the :scheduler: key"
25
+ end
26
+ elsif SIDEKIQ_GTE_6_5_0
27
+ unless sidekiq_config[option].nil?
28
+ raise OptionNotSupportedAnymore, ":#{option} option should be under the :scheduler: key"
29
+ end
30
+ else
31
+ if sidekiq_config.options.key?(option)
32
+ raise OptionNotSupportedAnymore, ":#{option} option should be under the :scheduler: key"
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ def self.start_schedule_manager(sidekiq_config:, schedule_manager:)
39
+ if SIDEKIQ_GTE_6_5_0
40
+ sidekiq_config[:schedule_manager] = schedule_manager
41
+ sidekiq_config[:schedule_manager].start
42
+ else
43
+ sidekiq_config.options[:schedule_manager] = schedule_manager
44
+ sidekiq_config.options[:schedule_manager].start
45
+ end
46
+ end
47
+
48
+ def self.stop_schedule_manager(sidekiq_config:)
49
+ if SIDEKIQ_GTE_6_5_0
50
+ sidekiq_config[:schedule_manager].stop
51
+ else
52
+ sidekiq_config.options[:schedule_manager].stop
53
+ end
54
+ end
55
+
56
+ def self.sidekiq_queues(sidekiq_config)
57
+ if SIDEKIQ_GTE_7_0_0
58
+ if sidekiq_config.nil? || (sidekiq_config.respond_to?(:empty?) && sidekiq_config.empty?)
59
+ Sidekiq.instance_variable_get(:@config).queues.map(&:to_s)
60
+ else
61
+ sidekiq_config.queues.map(&:to_s)
62
+ end
63
+ elsif SIDEKIQ_GTE_6_5_0
64
+ Sidekiq[:queues].map(&:to_s)
65
+ else
66
+ Sidekiq.options[:queues].map(&:to_s)
67
+ end
68
+ end
69
+
70
+ def self.redis_key_exists?(key_name)
71
+ Sidekiq.redis do |r|
72
+ if SIDEKIQ_GTE_7_0_0
73
+ r.exists(key_name) > 0
74
+ else
75
+ r.exists?(key_name)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,3 +1,3 @@
1
1
  module SidekiqScheduler
2
- VERSION = "4.0.3"
2
+ VERSION = "5.0.1"
3
3
  end
@@ -3,7 +3,7 @@ require 'sidekiq-scheduler'
3
3
  require_relative 'job_presenter'
4
4
 
5
5
  module SidekiqScheduler
6
- # Hook into *Sidekiq::Web* Sinatra app which adds a new '/recurring-jobs' page
6
+ # Hook into *Sidekiq::Web* app which adds a new '/recurring-jobs' page
7
7
 
8
8
  module Web
9
9
  VIEW_PATH = File.expand_path('../../../web/views', __FILE__)
@@ -5,9 +5,9 @@ require_relative 'sidekiq/scheduler'
5
5
  require_relative 'sidekiq-scheduler/version'
6
6
  require_relative 'sidekiq-scheduler/manager'
7
7
  require_relative 'sidekiq-scheduler/redis_manager'
8
+ require_relative 'sidekiq-scheduler/config'
8
9
  require_relative 'sidekiq-scheduler/extensions/schedule'
9
-
10
- SIDEKIQ_GTE_6_5_0 = Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new('6.5.0')
10
+ require_relative 'sidekiq-scheduler/sidekiq_adapter'
11
11
 
12
12
  Sidekiq.configure_server do |config|
13
13
 
@@ -15,25 +15,14 @@ Sidekiq.configure_server do |config|
15
15
  # schedules_changed's type was changed from SET to ZSET, so we remove old versions at startup
16
16
  SidekiqScheduler::RedisManager.clean_schedules_changed
17
17
 
18
- # Accessing the raw @config hash through .options is deprecated in 6.5 and to be removed in 7.0
19
- config_options = SIDEKIQ_GTE_6_5_0 ? Sidekiq.instance_variable_get(:@config) : config.options
18
+ scheduler_config = SidekiqScheduler::Config.new(sidekiq_config: config)
20
19
 
21
- schedule_manager = SidekiqScheduler::Manager.new(config_options)
22
- if SIDEKIQ_GTE_6_5_0
23
- config[:schedule_manager] = schedule_manager
24
- config[:schedule_manager].start
25
- else
26
- config.options[:schedule_manager] = schedule_manager
27
- config.options[:schedule_manager].start
28
- end
20
+ schedule_manager = SidekiqScheduler::Manager.new(scheduler_config)
21
+ SidekiqScheduler::SidekiqAdapter.start_schedule_manager(sidekiq_config: config, schedule_manager: schedule_manager)
29
22
  end
30
23
 
31
24
  config.on(:quiet) do
32
- if SIDEKIQ_GTE_6_5_0
33
- config[:schedule_manager].stop
34
- else
35
- config.options[:schedule_manager].stop
36
- end
25
+ SidekiqScheduler::SidekiqAdapter.stop_schedule_manager(sidekiq_config: config)
37
26
  end
38
27
 
39
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morton Jonuschat
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-10-05 00:00:00.000000000 Z
13
+ date: 2023-01-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sidekiq
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '4'
22
22
  - - "<"
23
23
  - !ruby/object:Gem::Version
24
- version: '7'
24
+ version: '8'
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,21 +31,7 @@ dependencies:
31
31
  version: '4'
32
32
  - - "<"
33
33
  - !ruby/object:Gem::Version
34
- version: '7'
35
- - !ruby/object:Gem::Dependency
36
- name: redis
37
- requirement: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: 4.2.0
42
- type: :runtime
43
- prerelease: false
44
- version_requirements: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: 4.2.0
34
+ version: '8'
49
35
  - !ruby/object:Gem::Dependency
50
36
  name: rufus-scheduler
51
37
  requirement: !ruby/object:Gem::Requirement
@@ -80,14 +66,14 @@ dependencies:
80
66
  requirements:
81
67
  - - "~>"
82
68
  - !ruby/object:Gem::Version
83
- version: '10.0'
69
+ version: '12.0'
84
70
  type: :development
85
71
  prerelease: false
86
72
  version_requirements: !ruby/object:Gem::Requirement
87
73
  requirements:
88
74
  - - "~>"
89
75
  - !ruby/object:Gem::Version
90
- version: '10.0'
76
+ version: '12.0'
91
77
  - !ruby/object:Gem::Dependency
92
78
  name: timecop
93
79
  requirement: !ruby/object:Gem::Requirement
@@ -187,19 +173,19 @@ dependencies:
187
173
  - !ruby/object:Gem::Version
188
174
  version: '0'
189
175
  - !ruby/object:Gem::Dependency
190
- name: sinatra
176
+ name: rack
191
177
  requirement: !ruby/object:Gem::Requirement
192
178
  requirements:
193
- - - ">="
179
+ - - "<"
194
180
  - !ruby/object:Gem::Version
195
- version: '0'
181
+ version: '3'
196
182
  type: :development
197
183
  prerelease: false
198
184
  version_requirements: !ruby/object:Gem::Requirement
199
185
  requirements:
200
- - - ">="
186
+ - - "<"
201
187
  - !ruby/object:Gem::Version
202
- version: '0'
188
+ version: '3'
203
189
  description: Light weight job scheduling extension for Sidekiq that adds support for
204
190
  queueing jobs in a recurring way.
205
191
  email:
@@ -214,6 +200,7 @@ files:
214
200
  - README.md
215
201
  - Rakefile
216
202
  - lib/sidekiq-scheduler.rb
203
+ - lib/sidekiq-scheduler/config.rb
217
204
  - lib/sidekiq-scheduler/extensions/schedule.rb
218
205
  - lib/sidekiq-scheduler/extensions/web.rb
219
206
  - lib/sidekiq-scheduler/job_presenter.rb
@@ -222,6 +209,7 @@ files:
222
209
  - lib/sidekiq-scheduler/rufus_utils.rb
223
210
  - lib/sidekiq-scheduler/schedule.rb
224
211
  - lib/sidekiq-scheduler/scheduler.rb
212
+ - lib/sidekiq-scheduler/sidekiq_adapter.rb
225
213
  - lib/sidekiq-scheduler/utils.rb
226
214
  - lib/sidekiq-scheduler/version.rb
227
215
  - lib/sidekiq-scheduler/web.rb
@@ -253,14 +241,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
253
241
  requirements:
254
242
  - - ">="
255
243
  - !ruby/object:Gem::Version
256
- version: '2.5'
244
+ version: '2.7'
257
245
  required_rubygems_version: !ruby/object:Gem::Requirement
258
246
  requirements:
259
247
  - - ">="
260
248
  - !ruby/object:Gem::Version
261
249
  version: '0'
262
250
  requirements: []
263
- rubygems_version: 3.1.6
251
+ rubygems_version: 3.2.33
264
252
  signing_key:
265
253
  specification_version: 4
266
254
  summary: Light weight job scheduling extension for Sidekiq