sidekiq-scheduler 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +168 -185
- data/lib/sidekiq-scheduler/rufus_utils.rb +29 -0
- data/lib/sidekiq-scheduler/version.rb +1 -1
- data/lib/sidekiq/scheduler.rb +7 -21
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e699dac84cd996f77b54a71564a2e888a5444c6d
|
4
|
+
data.tar.gz: 597847f71ef33050a54ded0d313204d3604f2742
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 933d343adcbb79210f95308de2b4612d4c0dd1185ea1b2b1d0fa9ae810b2e4a10031ef0d7b5ef90d95cf9168d742c9a9f4fa5369a87b3157397e9de0cc8b730f
|
7
|
+
data.tar.gz: 6813ae6ab82f3ffc24446734071114ad0ed446d15060bf8789b8ae98f6cfb44941c209bb9a1eb5875e8f6bc90a55a8050629ba15546c4972835f09421d63290a
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
<p align="center">
|
8
8
|
<a href="https://badge.fury.io/rb/sidekiq-scheduler">
|
9
|
-
<img src="https://badge.fury.io/rb/sidekiq-scheduler.
|
9
|
+
<img src="https://badge.fury.io/rb/sidekiq-scheduler.svg" alt="Gem Version">
|
10
10
|
</a>
|
11
11
|
<a href="https://codeclimate.com/github/moove-it/sidekiq-scheduler">
|
12
12
|
<img src="https://codeclimate.com/github/moove-it/sidekiq-scheduler/badges/gpa.svg" alt="Code Climate">
|
@@ -25,261 +25,213 @@
|
|
25
25
|
</a>
|
26
26
|
</p>
|
27
27
|
|
28
|
-
sidekiq-scheduler is an extension to [Sidekiq](http://github.com/mperham/sidekiq) that
|
29
|
-
|
28
|
+
`sidekiq-scheduler` is an extension to [Sidekiq](http://github.com/mperham/sidekiq) that
|
29
|
+
pushes jobs in a scheduled way, mimicking cron utility.
|
30
30
|
|
31
31
|
## Installation
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
``` ruby
|
36
|
-
gem 'sidekiq-scheduler', '~> 2.0'
|
33
|
+
``` shell
|
34
|
+
gem install sidekiq-scheduler
|
37
35
|
```
|
38
36
|
|
39
|
-
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
### Hello World
|
40
40
|
|
41
|
-
If you are not using Rails create a file with this content:
|
42
41
|
|
43
42
|
``` ruby
|
44
|
-
#
|
43
|
+
# hello-scheduler.rb
|
45
44
|
|
46
45
|
require 'sidekiq-scheduler'
|
47
46
|
|
48
|
-
|
47
|
+
class HelloWorld
|
48
|
+
include Sidekiq::Worker
|
49
|
+
|
50
|
+
def perform
|
51
|
+
puts 'Hello world'
|
52
|
+
end
|
53
|
+
end
|
49
54
|
```
|
50
55
|
|
51
|
-
|
56
|
+
``` yaml
|
57
|
+
# config/sidekiq.yml
|
52
58
|
|
53
|
-
|
54
|
-
|
59
|
+
:schedule:
|
60
|
+
hello_world:
|
61
|
+
every: 1m # Runs once per minute
|
62
|
+
class: HelloWorld
|
55
63
|
```
|
56
64
|
|
57
|
-
|
58
|
-
for information on how to load your schedule.
|
65
|
+
Run sidekiq:
|
59
66
|
|
60
|
-
|
61
|
-
|
67
|
+
``` sh
|
68
|
+
sidekiq -r ./hello-scheduler.rb
|
69
|
+
```
|
70
|
+
|
71
|
+
You'll see the following output:
|
62
72
|
|
63
|
-
``` yaml
|
64
|
-
:schedule: <the schedule to be run>
|
65
|
-
:dynamic: <if true the schedule can be modified in runtime [false by default]>
|
66
|
-
:enabled: <enables scheduler if true [true by default]>
|
67
|
-
:scheduler:
|
68
|
-
:listened_queues_only: <push jobs whose queue is being listened by sidekiq [false by default]>
|
69
73
|
```
|
74
|
+
2016-12-10T11:53:08.561Z 6452 TID-ovouhwvm4 INFO: Loading Schedule
|
75
|
+
2016-12-10T11:53:08.561Z 6452 TID-ovouhwvm4 INFO: Scheduling HelloWorld {"cron"=>"0 * * * * *", "class"=>"HelloWorld"}
|
76
|
+
2016-12-10T11:53:08.562Z 6452 TID-ovouhwvm4 INFO: Schedules Loaded
|
70
77
|
|
71
|
-
|
78
|
+
2016-12-10T11:54:00.212Z 6452 TID-ovoulivew HelloWorld JID-b35f36a562733fcc5e58444d INFO: start
|
79
|
+
Hello world
|
80
|
+
2016-12-10T11:54:00.213Z 6452 TID-ovoulivew HelloWorld JID-b35f36a562733fcc5e58444d INFO: done: 0.001 sec
|
72
81
|
|
73
|
-
|
74
|
-
|
82
|
+
2016-12-10T11:55:00.287Z 6452 TID-ovoulist0 HelloWorld JID-b7e2b244c258f3cd153c2494 INFO: start
|
83
|
+
Hello world
|
84
|
+
2016-12-10T11:55:00.287Z 6452 TID-ovoulist0 HelloWorld JID-b7e2b244c258f3cd153c2494 INFO: done: 0.001 sec
|
85
|
+
```
|
75
86
|
|
76
|
-
|
77
|
-
# config/initializers/sidekiq_scheduler.rb
|
78
|
-
require 'sidekiq/scheduler'
|
87
|
+
## Configuration options
|
79
88
|
|
80
|
-
|
81
|
-
puts "defined?(Rails::Server) is #{defined?(Rails::Server).inspect}"
|
82
|
-
puts "defined?(Unicorn) is #{defined?(Unicorn).inspect}"
|
89
|
+
Configuration options are placed inside `sidekiq.yml` config file.
|
83
90
|
|
84
|
-
|
85
|
-
Sidekiq.configure_server do |config|
|
91
|
+
Available options are:
|
86
92
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
else
|
93
|
-
Sidekiq::Scheduler.enabled = false
|
94
|
-
puts "Sidekiq::Scheduler.enabled is #{Sidekiq::Scheduler.enabled.inspect}"
|
95
|
-
end
|
93
|
+
``` yaml
|
94
|
+
:dynamic: <if true the schedule can be modified in runtime [false by default]>
|
95
|
+
:enabled: <enables scheduler if true [true by default]>
|
96
|
+
:scheduler:
|
97
|
+
:listened_queues_only: <push jobs whose queue is being listened by sidekiq [false by default]>
|
96
98
|
```
|
97
99
|
|
98
|
-
##
|
100
|
+
## Schedule configuration
|
99
101
|
|
100
|
-
|
101
|
-
job. They are jobs that run based on a fixed schedule which is set at
|
102
|
-
startup.
|
103
|
-
|
104
|
-
The schedule is a list of Sidekiq worker classes with arguments and a
|
105
|
-
schedule frequency (in crontab syntax). The schedule is just a Hash, being most likely
|
106
|
-
stored in a YAML like so:
|
102
|
+
The schedule is configured through the `:schedule` config entry in the sidekiq config file:
|
107
103
|
|
108
104
|
``` yaml
|
105
|
+
:schedule:
|
109
106
|
CancelAbandonedOrders:
|
110
|
-
|
107
|
+
every: 5m # runs every 5 minutes, job's class: CancelAbandonedOrders
|
111
108
|
|
112
109
|
queue_documents_for_indexing:
|
113
|
-
|
114
|
-
# you can use rufus-scheduler "every" syntax in place of cron if you prefer
|
115
|
-
# every: 1h
|
110
|
+
every: 1h # runs every 1 hour
|
116
111
|
|
117
|
-
# By default the job name
|
112
|
+
# By default the job name will be taken as worker class name.
|
118
113
|
# If you want to have a different job name and class name, provide the 'class' option
|
119
114
|
class: QueueDocuments
|
120
115
|
|
121
|
-
queue:
|
122
|
-
args:
|
123
|
-
description: "This job queues
|
116
|
+
queue: slow
|
117
|
+
args: ['*.pdf']
|
118
|
+
description: "This job queues pdf content for indexing in solr"
|
124
119
|
|
125
|
-
|
126
|
-
|
127
|
-
class: ClearLeaderboards
|
128
|
-
queue: low
|
129
|
-
args: contributors
|
130
|
-
description: "This job resets the weekly leaderboard for contributions"
|
120
|
+
# Enable / disable a job. All jobs are enabled by default.
|
121
|
+
enabled: true
|
131
122
|
```
|
132
123
|
|
133
|
-
You can provide options to `every` or `cron` via an Array:
|
134
124
|
|
135
|
-
|
136
|
-
clear_leaderboards_moderator:
|
137
|
-
every: ["30s", first_in: '120s']
|
138
|
-
class: CheckDaemon
|
139
|
-
queue: low
|
140
|
-
description: "This job will check Daemon every 30 seconds after 120 seconds after start"
|
141
|
-
```
|
125
|
+
## Schedule types
|
142
126
|
|
127
|
+
Supported types are `cron`, `every`, `interval`, `at`, `in`.
|
143
128
|
|
144
|
-
|
145
|
-
rufus-scheduler which powers the sidekiq-scheduler process). This allows you
|
146
|
-
to schedule jobs per second (ie: `30 * * * * *` would fire a job every 30
|
147
|
-
seconds past the minute).
|
129
|
+
Cron, every, and interval types push jobs into sidekiq in a recurrent manner.
|
148
130
|
|
149
|
-
|
150
|
-
for handling the heavy lifting of the actual scheduling engine.
|
131
|
+
`cron` follows the same pattern as cron utility, with seconds resolution.
|
151
132
|
|
152
|
-
|
153
|
-
|
154
|
-
|
133
|
+
``` yaml
|
134
|
+
:schedule:
|
135
|
+
HelloWorld:
|
136
|
+
cron: '0 * * * * *' # Runs when second = 0
|
137
|
+
```
|
155
138
|
|
156
|
-
|
157
|
-
`enabled` flag to `false`:
|
139
|
+
`every` triggers following a given frequency:
|
158
140
|
|
159
|
-
```yaml
|
160
|
-
:
|
141
|
+
``` yaml
|
142
|
+
every: '45m' # Runs every 45 minutes
|
161
143
|
```
|
162
|
-
### Enabling/Disabling jobs
|
163
144
|
|
164
|
-
|
165
|
-
|
145
|
+
`interval` is similar to `every`, the difference between them is that `interval` type schedules the
|
146
|
+
next execution after the interval has elapsed counting from its last job enqueue.
|
166
147
|
|
148
|
+
At, and in types push jobs only once. `at` schedules in a point in time:
|
167
149
|
``` yaml
|
168
|
-
|
169
|
-
every: "30s"
|
170
|
-
class: CheckDaemon
|
171
|
-
enabled: false
|
172
|
-
description: "This job is disabled by default"
|
150
|
+
at: '3001/01/01'
|
173
151
|
```
|
174
152
|
|
175
|
-
|
153
|
+
You can specify any string that `DateTime.parse` and `Chronic` understand. To enable Chronic
|
154
|
+
strings, you must add it as a dependency.
|
176
155
|
|
177
|
-
|
156
|
+
`in` triggers after a time duration has elapsed:
|
178
157
|
|
179
|
-
|
158
|
+
``` yaml
|
159
|
+
in: 1h # pushes a sidekiq job in 1 hour, after start-up
|
160
|
+
```
|
180
161
|
|
181
|
-
|
182
|
-
you could create a Rails initializer called `config/initializers/scheduler.rb` which would load the job definitions:
|
162
|
+
You can provide options to `every` or `cron` via an Array:
|
183
163
|
|
184
|
-
```
|
185
|
-
|
164
|
+
``` yaml
|
165
|
+
every: ['30s', first_in: '120s']
|
166
|
+
```
|
186
167
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
168
|
+
See https://github.com/jmettraux/rufus-scheduler for more information.
|
169
|
+
|
170
|
+
## Load the schedule from a different file
|
171
|
+
|
172
|
+
You can place the schedule configuration in a separate file from `config/sidekiq.yml`
|
173
|
+
|
174
|
+
``` yaml
|
175
|
+
# sidekiq_scheduler.yml
|
176
|
+
|
177
|
+
clear_leaderboards_contributors:
|
178
|
+
cron: '0 30 6 * * 1'
|
179
|
+
class: ClearLeaderboards
|
180
|
+
queue: low
|
181
|
+
args: contributors
|
182
|
+
description: 'This job resets the weekly leaderboard for contributions'
|
193
183
|
```
|
194
184
|
|
195
|
-
|
185
|
+
Please notice that the `schedule` root key is not present in the separate file.
|
196
186
|
|
197
|
-
|
187
|
+
To load the schedule:
|
188
|
+
|
189
|
+
``` ruby
|
190
|
+
require 'sidekiq'
|
198
191
|
require 'sidekiq/scheduler'
|
199
|
-
Dir[File.expand_path('../../../lib/workers/*.rb', __FILE__)].each do |file| load file; end
|
200
192
|
|
201
193
|
Sidekiq.configure_server do |config|
|
202
194
|
config.on(:startup) do
|
203
|
-
Sidekiq.schedule = YAML.load_file(File.expand_path(
|
195
|
+
Sidekiq.schedule = YAML.load_file(File.expand_path('../../sidekiq_scheduler.yml', __FILE__))
|
204
196
|
Sidekiq::Scheduler.reload_schedule!
|
205
197
|
end
|
206
198
|
end
|
207
199
|
```
|
208
200
|
|
209
|
-
|
210
|
-
|
211
|
-
```sh
|
212
|
-
sidekiq -C ./config/sidekiq.yml
|
213
|
-
```
|
214
|
-
|
215
|
-
#### The Spring preloader and Testing your initializer via Rails console
|
201
|
+
The above code can be placed in an initializer (in `config/initializers`) that runs every time the app starts up.
|
216
202
|
|
217
|
-
|
218
|
-
|
219
|
-
**Spring will not reload initializers** unless the initializer is changed. Therefore, if you're making a change to your YML schedule file and reloading Rails console to see the change, Spring will make it seem like your modified schedule is not being reloaded.
|
220
|
-
|
221
|
-
To see your updated schedule, be sure to reload Spring by stopping it prior to booting the Rails console.
|
222
|
-
|
223
|
-
Run `spring stop` to stop Spring.
|
224
|
-
|
225
|
-
For more information, see [this issue](https://github.com/Moove-it/sidekiq-scheduler/issues/35#issuecomment-48067183) and [Spring's README](https://github.com/rails/spring/blob/master/README.md).
|
203
|
+
## Dynamic schedule
|
226
204
|
|
227
|
-
|
205
|
+
The schedule can be modified after startup. To add / update a schedule, you have to:
|
228
206
|
|
229
|
-
|
230
|
-
|
231
|
-
```ruby
|
207
|
+
``` ruby
|
232
208
|
Sidekiq.set_schedule('heartbeat', { 'every' => ['1m'], 'class' => 'HeartbeatWorker' })
|
233
209
|
```
|
234
210
|
|
235
|
-
|
211
|
+
If the schedule did not exist it will be created, if it existed it will be updated.
|
236
212
|
|
237
|
-
|
238
|
-
|
239
|
-
- YAML configuration:
|
213
|
+
When `:dynamic` flag is set to `true`, schedule changes are loaded every 5 seconds.
|
240
214
|
|
241
|
-
```
|
215
|
+
``` yaml
|
216
|
+
# config/sidekiq.yml
|
242
217
|
:dynamic: true
|
243
218
|
```
|
244
219
|
|
245
|
-
|
246
|
-
|
247
|
-
```ruby
|
248
|
-
Sidekiq.configure_server do |config|
|
249
|
-
# ...
|
250
|
-
Sidekiq::Scheduler.dynamic = true
|
251
|
-
end
|
252
|
-
```
|
253
|
-
|
254
|
-
If `:dynamic` flag is set to `false`, you have to reload the schedule manually in sidekiq
|
220
|
+
If `:dynamic` flag is set to `false`, you'll have to reload the schedule manually in sidekiq
|
255
221
|
side:
|
256
222
|
|
257
|
-
```ruby
|
223
|
+
``` ruby
|
258
224
|
Sidekiq::Scheduler.reload_schedule!
|
259
225
|
```
|
260
226
|
|
261
|
-
|
262
|
-
|
263
|
-
### Testing
|
264
|
-
|
265
|
-
In your tests you can check that a schedule change has been set you have to:
|
266
|
-
|
267
|
-
```ruby
|
268
|
-
require 'sidekiq'
|
269
|
-
require 'sidekiq-scheduler'
|
270
|
-
require 'sidekiq-scheduler/test'
|
271
|
-
|
272
|
-
Sidekiq.set_schedule('some_name', { 'every' => ['1m'], 'class' => 'HardWorker' })
|
273
|
-
|
274
|
-
Sidekiq::Scheduler.schedules
|
275
|
-
# => { 'every' => ['1m'], 'class' => 'HardWorker' }
|
227
|
+
Invoke `Sidekiq.get_schedule` to obtain the current schedule:
|
276
228
|
|
277
|
-
|
278
|
-
|
229
|
+
``` ruby
|
230
|
+
Sidekiq.get_schedule
|
231
|
+
# => { 'every' => '1m', 'class' => 'HardWorker' }
|
279
232
|
```
|
280
233
|
|
281
|
-
|
282
|
-
### Time zones
|
234
|
+
## Time zones
|
283
235
|
|
284
236
|
Note that if you use the cron syntax, this will be interpreted as in the server time zone
|
285
237
|
rather than the `config.time_zone` specified in Rails.
|
@@ -287,7 +239,7 @@ rather than the `config.time_zone` specified in Rails.
|
|
287
239
|
You can explicitly specify the time zone that rufus-scheduler will use:
|
288
240
|
|
289
241
|
``` yaml
|
290
|
-
cron:
|
242
|
+
cron: '0 30 6 * * 1 Europe/Stockholm'
|
291
243
|
```
|
292
244
|
|
293
245
|
Also note that `config.time_zone` in Rails allows for a shorthand (e.g. "Stockholm")
|
@@ -298,32 +250,63 @@ from the `config.time_zone` value, make sure it's the right format, e.g. with:
|
|
298
250
|
ActiveSupport::TimeZone.find_tzinfo(Rails.configuration.time_zone).name
|
299
251
|
```
|
300
252
|
|
301
|
-
|
302
|
-
|
303
|
-
### Sidekiq Web Integration
|
253
|
+
## Sidekiq Web Integration
|
304
254
|
|
305
|
-
|
306
|
-
|
307
|
-
To use it, set up the Sidekiq web interface according to the Sidekiq documentation and then add the `sidekiq-scheduler/web` require:
|
255
|
+
sidekiq-scheduler provides an extension to the Sidekiq web interface that adds a `Recurring Jobs` page.
|
308
256
|
|
309
257
|
``` ruby
|
258
|
+
# config.ru
|
259
|
+
|
310
260
|
require 'sidekiq/web'
|
261
|
+
require 'sidekiq-scheduler'
|
311
262
|
require 'sidekiq-scheduler/web'
|
263
|
+
|
264
|
+
app = Rack::Builder.new {
|
265
|
+
run Sidekiq::Web
|
266
|
+
}.to_app
|
267
|
+
|
268
|
+
Rack::Handler::WEBrick.run app
|
312
269
|
```
|
313
270
|
|
314
|
-
##
|
271
|
+
## The Spring preloader and Testing your initializer via Rails console
|
272
|
+
|
273
|
+
If you're pulling in your schedule from a YML file via an initializer as shown, be aware that the Spring application preloader included with Rails will interefere with testing via the Rails console.
|
274
|
+
|
275
|
+
**Spring will not reload initializers** unless the initializer is changed. Therefore, if you're making a change to your YML schedule file and reloading Rails console to see the change, Spring will make it seem like your modified schedule is not being reloaded.
|
276
|
+
|
277
|
+
To see your updated schedule, be sure to reload Spring by stopping it prior to booting the Rails console.
|
278
|
+
|
279
|
+
Run `spring stop` to stop Spring.
|
280
|
+
|
281
|
+
For more information, see [this issue](https://github.com/Moove-it/sidekiq-scheduler/issues/35#issuecomment-48067183) and [Spring's README](https://github.com/rails/spring/blob/master/README.md).
|
315
282
|
|
316
|
-
* Fork the project.
|
317
|
-
* Make your feature addition or bug fix.
|
318
|
-
* Add tests for it. This is important so it won't break it in a future version unintentionally.
|
319
|
-
* Commit, do not mess with version, or history.
|
320
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself so it can be ignored when merging)
|
321
|
-
* Send a pull request. Bonus points for topic branches.
|
322
283
|
|
323
|
-
##
|
284
|
+
## Manage tasks from Unicorn/Rails server
|
285
|
+
|
286
|
+
If you want start sidekiq-scheduler only from Unicorn/Rails, but not from sidekiq you can have
|
287
|
+
something like this in an initializer:
|
288
|
+
|
289
|
+
``` ruby
|
290
|
+
# config/initializers/sidekiq_scheduler.rb
|
291
|
+
require 'sidekiq/scheduler'
|
324
292
|
|
325
|
-
|
326
|
-
|
293
|
+
puts "Sidekiq.server? is #{Sidekiq.server?.inspect}"
|
294
|
+
puts "defined?(Rails::Server) is #{defined?(Rails::Server).inspect}"
|
295
|
+
puts "defined?(Unicorn) is #{defined?(Unicorn).inspect}"
|
296
|
+
|
297
|
+
if Rails.env == 'production' && (defined?(Rails::Server) || defined?(Unicorn))
|
298
|
+
Sidekiq.configure_server do |config|
|
299
|
+
|
300
|
+
config.on(:startup) do
|
301
|
+
Sidekiq.schedule = YAML.load_file(File.expand_path('../../scheduler.yml', __FILE__))
|
302
|
+
Sidekiq::Scheduler.reload_schedule!
|
303
|
+
end
|
304
|
+
end
|
305
|
+
else
|
306
|
+
Sidekiq::Scheduler.enabled = false
|
307
|
+
puts "Sidekiq::Scheduler.enabled is #{Sidekiq::Scheduler.enabled.inspect}"
|
308
|
+
end
|
309
|
+
```
|
327
310
|
|
328
311
|
## License
|
329
312
|
|
@@ -331,6 +314,6 @@ MIT License
|
|
331
314
|
|
332
315
|
## Copyright
|
333
316
|
|
334
|
-
Copyright 2013 -
|
317
|
+
Copyright 2013 - 2017 Moove-IT.
|
335
318
|
Copyright 2012 Morton Jonuschat.
|
336
319
|
Some parts copyright 2010 Ben VandenBos.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module SidekiqScheduler
|
4
|
+
class RufusUtils
|
5
|
+
|
6
|
+
# Normalizes schedule options to rufust scheduler options
|
7
|
+
#
|
8
|
+
# @param options [String, [Array]
|
9
|
+
#
|
10
|
+
# @return [Array]
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# normalize_schedule_options('15m') => ['15m', {}]
|
14
|
+
# normalize_schedule_options(['15m']) => ['15m', {}]
|
15
|
+
# normalize_schedule_options(['15m', first_in: '5m']) => ['15m', { first_in: '5m' }]
|
16
|
+
def self.normalize_schedule_options(options)
|
17
|
+
schedule, opts = options
|
18
|
+
|
19
|
+
if !opts.is_a?(Hash)
|
20
|
+
opts = {}
|
21
|
+
end
|
22
|
+
|
23
|
+
opts = Hashie.symbolize_keys(opts)
|
24
|
+
|
25
|
+
return schedule, opts
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
data/lib/sidekiq/scheduler.rb
CHANGED
@@ -2,6 +2,7 @@ require 'rufus/scheduler'
|
|
2
2
|
require 'thwait'
|
3
3
|
require 'sidekiq/util'
|
4
4
|
require 'sidekiq-scheduler/manager'
|
5
|
+
require 'sidekiq-scheduler/rufus_utils'
|
5
6
|
require 'json'
|
6
7
|
|
7
8
|
module Sidekiq
|
@@ -79,21 +80,6 @@ module Sidekiq
|
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
82
|
-
# modify interval type value to value with options if options available
|
83
|
-
def optionizate_interval_value(value)
|
84
|
-
args = value
|
85
|
-
if args.is_a?(::Array)
|
86
|
-
return args.first if args.size > 2 || !args.last.is_a?(::Hash)
|
87
|
-
# symbolize keys of hash for options
|
88
|
-
args[1] = args[1].inject({}) do |m, i|
|
89
|
-
key, value = i
|
90
|
-
m[(key.to_sym rescue key) || key] = value
|
91
|
-
m
|
92
|
-
end
|
93
|
-
end
|
94
|
-
args
|
95
|
-
end
|
96
|
-
|
97
83
|
# Loads a job schedule into the Rufus::Scheduler and stores it in @@scheduled_jobs
|
98
84
|
def load_schedule_job(name, config)
|
99
85
|
# If rails_env is set in the config, enforce ENV['RAILS_ENV'] as
|
@@ -109,9 +95,9 @@ module Sidekiq
|
|
109
95
|
|
110
96
|
if !config_interval_type.nil? && config_interval_type.length > 0
|
111
97
|
|
112
|
-
|
98
|
+
schedule, options = SidekiqScheduler::RufusUtils.normalize_schedule_options(config_interval_type)
|
113
99
|
|
114
|
-
rufus_job = new_job(name, interval_type, config,
|
100
|
+
rufus_job = new_job(name, interval_type, config, schedule, options)
|
115
101
|
@@scheduled_jobs[name] = rufus_job
|
116
102
|
update_job_next_time(name, rufus_job.next_time)
|
117
103
|
|
@@ -224,7 +210,7 @@ module Sidekiq
|
|
224
210
|
unschedule_job(schedule_name)
|
225
211
|
end
|
226
212
|
end
|
227
|
-
logger.info '
|
213
|
+
logger.info 'Schedule updated'
|
228
214
|
end
|
229
215
|
end
|
230
216
|
|
@@ -369,10 +355,10 @@ module Sidekiq
|
|
369
355
|
end
|
370
356
|
end
|
371
357
|
|
372
|
-
def new_job(name, interval_type, config,
|
373
|
-
|
358
|
+
def new_job(name, interval_type, config, schedule, options)
|
359
|
+
options = options.merge({ :job => true, :tags => [name] })
|
374
360
|
|
375
|
-
rufus_scheduler.send(interval_type,
|
361
|
+
rufus_scheduler.send(interval_type, schedule, options) do |job, time|
|
376
362
|
idempotent_job_enqueue(name, time, sanitize_job_config(config)) if job_enabled?(name)
|
377
363
|
end
|
378
364
|
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.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Morton Jonuschat
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-02-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hashie
|
@@ -249,6 +249,7 @@ files:
|
|
249
249
|
- lib/sidekiq-scheduler.rb
|
250
250
|
- lib/sidekiq-scheduler/job_presenter.rb
|
251
251
|
- lib/sidekiq-scheduler/manager.rb
|
252
|
+
- lib/sidekiq-scheduler/rufus_utils.rb
|
252
253
|
- lib/sidekiq-scheduler/schedule.rb
|
253
254
|
- lib/sidekiq-scheduler/version.rb
|
254
255
|
- lib/sidekiq-scheduler/web.rb
|