sidekiq-scheduler 2.0.21 → 2.1.0

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
  SHA1:
3
- metadata.gz: a7a5d01719af50b7da30cfde9098acd849c3a89b
4
- data.tar.gz: 1a8e7a1b4bdb3d1ae260ed19b5541e69ce2ffa97
3
+ metadata.gz: 5f61962caca434778af22dffae98cdbb9c154774
4
+ data.tar.gz: 7ecd8c8fc1b61780593346b11f88f719d900cddf
5
5
  SHA512:
6
- metadata.gz: 6516a4ee19622497140bb3ae0226905f2dcd1b49462ebb1d753e350e4d397cda6f21fa024212871c16bce90507ca34908ee1d9abcac055cb9cfe25c40dcd3811
7
- data.tar.gz: e77aa42c1610e4927e9b8e9a87aff1b2b9fd05f41818aaef5bcef900d62a695edcce0ef6b66a008189c9b749b7147c7acc716bfbae06e7cb02f8371e26a694ac
6
+ metadata.gz: 11efa51145977a60adf4238a316a2e906ffe3f7767ea5ac15a30f1b7fd2f0331412db631371e91ca48869609c9fa6142621df190c962e1a74fc6eb95c3d34703
7
+ data.tar.gz: 1086eb5cdfb1920a3d6f713a793939cccf62c74a8c235aedc598ba6216ec9fc3eb97967f2e962fa6b5c2e7c20b32492a10d48a009558e726e84c0f0cb28915bd
data/README.md CHANGED
@@ -32,23 +32,27 @@ for running scheduled jobs, which are like cron jobs, recurring on a regular bas
32
32
 
33
33
  Add this to your Gemfile:
34
34
 
35
- ```ruby
35
+ ``` ruby
36
36
  gem 'sidekiq-scheduler', '~> 2.0'
37
- ```
37
+ ```
38
38
 
39
39
  If you are using Rails you are set.
40
40
 
41
41
  If you are not using Rails create a file with this content:
42
42
 
43
- ```ruby
43
+ ``` ruby
44
+ # config/initializers/scheduler.rb
45
+
44
46
  require 'sidekiq-scheduler'
45
- ```
47
+
48
+ Dir[File.join(__dir__, '../../lib/workers/**/*.rb')].each(&method(:require))
49
+ ```
46
50
 
47
51
  and then execute:
48
52
 
49
- ```sh
50
- sidekiq -r created_file_path.rb
51
- ```
53
+ ``` sh
54
+ sidekiq -r ./config/initializers/scheduler.rb
55
+ ```
52
56
 
53
57
  Look at [Loading the schedule](https://github.com/moove-it/sidekiq-scheduler/#loading-the-schedule)
54
58
  for information on how to load your schedule.
@@ -69,7 +73,7 @@ Available options are:
69
73
  If you want start sidekiq-scheduler only from Unicorn/Rails, but not from Sidekiq you can have
70
74
  something like this in an initializer:
71
75
 
72
- ```ruby
76
+ ``` ruby
73
77
  # config/initializers/sidekiq_scheduler.rb
74
78
  require 'sidekiq/scheduler'
75
79
 
@@ -130,9 +134,9 @@ You can provide options to `every` or `cron` via an Array:
130
134
 
131
135
  ``` yaml
132
136
  clear_leaderboards_moderator:
133
- every: ["30s", :first_in => '120s']
137
+ every: ["30s", first_in: '120s']
134
138
  class: CheckDaemon
135
- queue: daemons
139
+ queue: low
136
140
  description: "This job will check Daemon every 30 seconds after 120 seconds after start"
137
141
  ```
138
142
 
@@ -182,7 +186,7 @@ require 'sidekiq/scheduler'
182
186
 
183
187
  Sidekiq.configure_server do |config|
184
188
  config.on(:startup) do
185
- Sidekiq.schedule = YAML.load_file(File.expand_path('../../sidekiq_scheduler.yml', __FILE__))
189
+ Sidekiq.schedule = YAML.load_file(File.expand_path('../../scheduler.yml', __FILE__))
186
190
  Sidekiq::Scheduler.reload_schedule!
187
191
  end
188
192
  end
@@ -320,7 +324,6 @@ require 'sidekiq-scheduler/web'
320
324
 
321
325
  This work is a partial port of [resque-scheduler](https://github.com/bvandenbos/resque-scheduler) by Ben VandenBos.
322
326
  Modified to work with the Sidekiq queueing library by Morton Jonuschat.
323
- Scheduling of recurring jobs has been added to v0.4.0, thanks to [Adrian Gomez](https://github.com/adrian-gomez).
324
327
 
325
328
  ## License
326
329
 
@@ -328,6 +331,6 @@ MIT License
328
331
 
329
332
  ## Copyright
330
333
 
331
- Copyright 2013 - 2016 Moove-IT
332
- Copyright 2012 Morton Jonuschat
333
- Some parts copyright 2010 Ben VandenBos
334
+ Copyright 2013 - 2016 Moove-IT.
335
+ Copyright 2012 Morton Jonuschat.
336
+ Some parts copyright 2010 Ben VandenBos.
@@ -71,7 +71,7 @@ module SidekiqScheduler
71
71
  get_all_schedules
72
72
  else
73
73
  encoded_schedule = Sidekiq.redis { |r| r.hget(:schedules, name) }
74
- encoded_schedule.nil? ? nil : JSON(encoded_schedule)
74
+ encoded_schedule.nil? ? nil : JSON.parse(encoded_schedule)
75
75
  end
76
76
  end
77
77
 
@@ -82,7 +82,7 @@ module SidekiqScheduler
82
82
  if Sidekiq.redis { |r| r.exists(:schedules) }
83
83
  Sidekiq.redis { |r| r.hgetall(:schedules) }.tap do |h|
84
84
  h.each do |name, config|
85
- schedules[name] = JSON(config)
85
+ schedules[name] = JSON.parse(config)
86
86
  end
87
87
  end
88
88
  end
@@ -102,7 +102,7 @@ module SidekiqScheduler
102
102
  def set_schedule(name, config)
103
103
  existing_config = get_schedule(name)
104
104
  unless existing_config && existing_config == config
105
- Sidekiq.redis { |r| r.hset(:schedules, name, JSON(config)) }
105
+ Sidekiq.redis { |r| r.hset(:schedules, name, JSON.generate(config)) }
106
106
  Sidekiq.redis { |r| r.sadd(:schedules_changed, name) }
107
107
  end
108
108
  config
@@ -123,11 +123,33 @@ module SidekiqScheduler
123
123
 
124
124
  schedule_hash.each do |name, job_spec|
125
125
  job_spec = job_spec.dup
126
- job_spec['class'] = name unless job_spec.key?('class') || job_spec.key?(:class)
126
+
127
+ job_class = job_spec.fetch('class', name)
128
+ inferred_queue = infer_queue(job_class)
129
+
130
+ job_spec['class'] ||= job_class
131
+ job_spec['queue'] ||= inferred_queue unless inferred_queue.nil?
132
+
127
133
  prepared_hash[name] = job_spec
128
134
  end
129
135
  prepared_hash
130
136
  end
137
+
138
+ def infer_queue(klass)
139
+ klass = try_to_constantize(klass)
140
+
141
+ if klass.respond_to?(:sidekiq_options)
142
+ klass.sidekiq_options['queue']
143
+ elsif klass.respond_to?(:queue_name)
144
+ klass.queue_name
145
+ end
146
+ end
147
+
148
+ def try_to_constantize(klass)
149
+ klass.is_a?(String) ? klass.constantize : klass
150
+ rescue NameError
151
+ klass
152
+ end
131
153
  end
132
154
  end
133
155
 
@@ -1,5 +1,5 @@
1
1
  module SidekiqScheduler
2
2
 
3
- VERSION = '2.0.21'
3
+ VERSION = '2.1.0'
4
4
 
5
5
  end
@@ -388,7 +388,7 @@ module Sidekiq
388
388
  def schedule_state(name)
389
389
  state = Sidekiq.redis { |r| r.hget(schedules_state_key, name) }
390
390
 
391
- state ? JSON(state) : {}
391
+ state ? JSON.parse(state) : {}
392
392
  end
393
393
 
394
394
  # Saves a schedule state
@@ -396,7 +396,7 @@ module Sidekiq
396
396
  # @param name [String] with the schedule's name
397
397
  # @param name [Hash] with the schedule's state
398
398
  def set_schedule_state(name, state)
399
- Sidekiq.redis { |r| r.hset(schedules_state_key, name, JSON(state)) }
399
+ Sidekiq.redis { |r| r.hset(schedules_state_key, name, JSON.generate(state)) }
400
400
  end
401
401
 
402
402
  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: 2.0.21
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morton Jonuschat
@@ -9,230 +9,230 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-11-14 00:00:00.000000000 Z
12
+ date: 2017-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hashie
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '3.4'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '3.4'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: sidekiq
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '3'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '3'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: redis
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
48
  version: '3'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ~>
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '3'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rufus-scheduler
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ~>
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: 3.1.8
62
+ version: '3.2'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ~>
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: 3.1.8
69
+ version: '3.2'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: tilt
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - '>='
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: 1.4.0
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - '>='
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: 1.4.0
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: rake
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - ~>
88
+ - - "~>"
89
89
  - !ruby/object:Gem::Version
90
90
  version: '10.0'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - ~>
95
+ - - "~>"
96
96
  - !ruby/object:Gem::Version
97
97
  version: '10.0'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: timecop
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ~>
102
+ - - "~>"
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ~>
109
+ - - "~>"
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: mocha
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ~>
116
+ - - "~>"
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - ~>
123
+ - - "~>"
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: rspec
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - '>='
130
+ - - ">="
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
- - - '>='
137
+ - - ">="
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: mock_redis
142
142
  requirement: !ruby/object:Gem::Requirement
143
143
  requirements:
144
- - - ~>
144
+ - - "~>"
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  type: :development
148
148
  prerelease: false
149
149
  version_requirements: !ruby/object:Gem::Requirement
150
150
  requirements:
151
- - - ~>
151
+ - - "~>"
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  - !ruby/object:Gem::Dependency
155
155
  name: simplecov
156
156
  requirement: !ruby/object:Gem::Requirement
157
157
  requirements:
158
- - - ~>
158
+ - - "~>"
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  type: :development
162
162
  prerelease: false
163
163
  version_requirements: !ruby/object:Gem::Requirement
164
164
  requirements:
165
- - - ~>
165
+ - - "~>"
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: byebug
170
170
  requirement: !ruby/object:Gem::Requirement
171
171
  requirements:
172
- - - '>='
172
+ - - ">="
173
173
  - !ruby/object:Gem::Version
174
174
  version: '0'
175
175
  type: :development
176
176
  prerelease: false
177
177
  version_requirements: !ruby/object:Gem::Requirement
178
178
  requirements:
179
- - - '>='
179
+ - - ">="
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
182
  - !ruby/object:Gem::Dependency
183
183
  name: activejob
184
184
  requirement: !ruby/object:Gem::Requirement
185
185
  requirements:
186
- - - <
186
+ - - ">="
187
187
  - !ruby/object:Gem::Version
188
- version: '5'
188
+ version: '0'
189
189
  type: :development
190
190
  prerelease: false
191
191
  version_requirements: !ruby/object:Gem::Requirement
192
192
  requirements:
193
- - - <
193
+ - - ">="
194
194
  - !ruby/object:Gem::Version
195
- version: '5'
195
+ version: '0'
196
196
  - !ruby/object:Gem::Dependency
197
197
  name: coveralls
198
198
  requirement: !ruby/object:Gem::Requirement
199
199
  requirements:
200
- - - '>='
200
+ - - ">="
201
201
  - !ruby/object:Gem::Version
202
202
  version: '0'
203
203
  type: :development
204
204
  prerelease: false
205
205
  version_requirements: !ruby/object:Gem::Requirement
206
206
  requirements:
207
- - - '>='
207
+ - - ">="
208
208
  - !ruby/object:Gem::Version
209
209
  version: '0'
210
210
  - !ruby/object:Gem::Dependency
211
211
  name: rack-test
212
212
  requirement: !ruby/object:Gem::Requirement
213
213
  requirements:
214
- - - '>='
214
+ - - ">="
215
215
  - !ruby/object:Gem::Version
216
216
  version: '0'
217
217
  type: :development
218
218
  prerelease: false
219
219
  version_requirements: !ruby/object:Gem::Requirement
220
220
  requirements:
221
- - - '>='
221
+ - - ">="
222
222
  - !ruby/object:Gem::Version
223
223
  version: '0'
224
224
  - !ruby/object:Gem::Dependency
225
225
  name: sinatra
226
226
  requirement: !ruby/object:Gem::Requirement
227
227
  requirements:
228
- - - '>='
228
+ - - ">="
229
229
  - !ruby/object:Gem::Version
230
230
  version: '0'
231
231
  type: :development
232
232
  prerelease: false
233
233
  version_requirements: !ruby/object:Gem::Requirement
234
234
  requirements:
235
- - - '>='
235
+ - - ">="
236
236
  - !ruby/object:Gem::Version
237
237
  version: '0'
238
238
  description: Light weight job scheduling extension for Sidekiq that adds support for
@@ -243,21 +243,21 @@ executables: []
243
243
  extensions: []
244
244
  extra_rdoc_files: []
245
245
  files:
246
+ - MIT-LICENSE
247
+ - README.md
248
+ - Rakefile
246
249
  - lib/sidekiq-scheduler.rb
247
- - lib/sidekiq/scheduler.rb
248
- - lib/sidekiq-scheduler/schedule.rb
249
- - lib/sidekiq-scheduler/version.rb
250
250
  - lib/sidekiq-scheduler/job_presenter.rb
251
251
  - lib/sidekiq-scheduler/manager.rb
252
+ - lib/sidekiq-scheduler/schedule.rb
253
+ - lib/sidekiq-scheduler/version.rb
252
254
  - lib/sidekiq-scheduler/web.rb
253
- - web/views/recurring_jobs.erb
255
+ - lib/sidekiq/scheduler.rb
254
256
  - web/locales/cs.yml
255
257
  - web/locales/en.yml
256
- - web/locales/zh-cn.yml
257
258
  - web/locales/es.yml
258
- - MIT-LICENSE
259
- - Rakefile
260
- - README.md
259
+ - web/locales/zh-cn.yml
260
+ - web/views/recurring_jobs.erb
261
261
  homepage: https://github.com/moove-it/sidekiq-scheduler
262
262
  licenses:
263
263
  - MIT
@@ -268,17 +268,17 @@ require_paths:
268
268
  - lib
269
269
  required_ruby_version: !ruby/object:Gem::Requirement
270
270
  requirements:
271
- - - '>='
271
+ - - ">="
272
272
  - !ruby/object:Gem::Version
273
273
  version: '0'
274
274
  required_rubygems_version: !ruby/object:Gem::Requirement
275
275
  requirements:
276
- - - '>='
276
+ - - ">="
277
277
  - !ruby/object:Gem::Version
278
278
  version: '0'
279
279
  requirements: []
280
280
  rubyforge_project:
281
- rubygems_version: 2.0.14.1
281
+ rubygems_version: 2.5.1
282
282
  signing_key:
283
283
  specification_version: 4
284
284
  summary: Light weight job scheduling extension for Sidekiq