sidekiq-scheduler 2.0.7 → 2.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +92 -71
- data/lib/sidekiq-scheduler/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2ca5f12c843c8653e3a174431625f89622daee3
|
4
|
+
data.tar.gz: e479e32ea285d53200078971da9b1eb3e7dfd323
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ab648c207104060b36cfebb38fae68bb8af05b63ab2760485d6b958e1145312b7b1ceca631089eb297d8a84f6963969920e04f36e5fc9f641f45635b58d5c10
|
7
|
+
data.tar.gz: ef5e376ba307b8b0fc62c6fcb61b7be50c50cd37971715e501de8220dad7e8743dfb5856ba18c10aa963c990827d194b807df2fe45927a38c3027aa7310a247b
|
data/README.md
CHANGED
@@ -25,45 +25,49 @@
|
|
25
25
|
</a>
|
26
26
|
</p>
|
27
27
|
|
28
|
-
sidekiq-scheduler is an extension to [Sidekiq](http://github.com/mperham/sidekiq)
|
29
|
-
|
30
|
-
|
31
|
-
Scheduled jobs are like cron jobs, recurring on a regular basis.
|
28
|
+
sidekiq-scheduler is an extension to [Sidekiq](http://github.com/mperham/sidekiq) that adds support
|
29
|
+
for running scheduled jobs, which are like cron jobs, recurring on a regular basis.
|
32
30
|
|
33
31
|
## Installation
|
34
32
|
|
35
33
|
Add this to your Gemfile:
|
34
|
+
|
36
35
|
```ruby
|
37
36
|
gem 'sidekiq-scheduler', '~> 2.0'
|
38
|
-
```
|
37
|
+
```
|
39
38
|
|
40
|
-
If you are using
|
39
|
+
If you are using Rails you are set.
|
40
|
+
|
41
|
+
If you are not using Rails create a file with this content:
|
41
42
|
|
42
|
-
If you are not using rails create a file with this content:
|
43
43
|
```ruby
|
44
44
|
require 'sidekiq-scheduler'
|
45
|
-
```
|
45
|
+
```
|
46
|
+
|
47
|
+
and then execute:
|
46
48
|
|
47
|
-
and the execute:
|
48
49
|
```sh
|
49
50
|
sidekiq -r created_file_path.rb
|
50
|
-
```
|
51
|
+
```
|
51
52
|
|
52
53
|
Look at [Loading the schedule](https://github.com/moove-it/sidekiq-scheduler/#loading-the-schedule)
|
53
54
|
for information on how to load your schedule.
|
54
55
|
|
55
|
-
You can add sidekiq-scheduler configuration options to sidekiq.yml config file.
|
56
|
+
You can add sidekiq-scheduler configuration options to `sidekiq.yml` config file.
|
56
57
|
Available options are:
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
``` yaml
|
60
|
+
:schedule: <the schedule to be run>
|
61
|
+
:dynamic: <if true the schedule can be modified in runtime [false by default]>
|
62
|
+
:enabled: <enables scheduler if true [true by default]>
|
63
|
+
:scheduler:
|
64
|
+
:listened_queues_only: <push jobs whose queue is being listened by sidekiq [false by default]>
|
65
|
+
```
|
63
66
|
|
64
67
|
## Manage tasks from Unicorn/Rails server
|
65
68
|
|
66
|
-
|
69
|
+
If you want start sidekiq-scheduler only from Unicorn/Rails, but not from Sidekiq you can have
|
70
|
+
something like this in an initializer:
|
67
71
|
|
68
72
|
```ruby
|
69
73
|
# config/initializers/sidekiq_scheduler.rb
|
@@ -91,46 +95,52 @@ end
|
|
91
95
|
## Scheduled Jobs (Recurring Jobs)
|
92
96
|
|
93
97
|
Scheduled (or recurring) jobs are logically no different than a standard cron
|
94
|
-
job.
|
98
|
+
job. They are jobs that run based on a fixed schedule which is set at
|
95
99
|
startup.
|
96
100
|
|
97
101
|
The schedule is a list of Sidekiq worker classes with arguments and a
|
98
|
-
schedule frequency (in crontab syntax).
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
102
|
+
schedule frequency (in crontab syntax). The schedule is just a Hash, being most likely
|
103
|
+
stored in a YAML like so:
|
104
|
+
|
105
|
+
``` yaml
|
106
|
+
CancelAbandonedOrders:
|
107
|
+
cron: "*/5 * * * *"
|
108
|
+
|
109
|
+
queue_documents_for_indexing:
|
110
|
+
cron: "0 0 * * *"
|
111
|
+
# you can use rufus-scheduler "every" syntax in place of cron if you prefer
|
112
|
+
# every: 1h
|
113
|
+
|
114
|
+
# By default the job name (Hash key) will be taken as worker class name.
|
115
|
+
# If you want to have a different job name and class name, provide the 'class' option
|
116
|
+
class: QueueDocuments
|
117
|
+
|
118
|
+
queue: high
|
119
|
+
args:
|
120
|
+
description: "This job queues all content for indexing in solr"
|
121
|
+
|
122
|
+
clear_leaderboards_contributors:
|
123
|
+
cron: "30 6 * * 1"
|
124
|
+
class: ClearLeaderboards
|
125
|
+
queue: low
|
126
|
+
args: contributors
|
127
|
+
description: "This job resets the weekly leaderboard for contributions"
|
128
|
+
```
|
129
|
+
|
130
|
+
You can provide options to `every` or `cron` via an Array:
|
131
|
+
|
132
|
+
``` yaml
|
133
|
+
clear_leaderboards_moderator:
|
134
|
+
every: ["30s", :first_in => '120s']
|
135
|
+
class: CheckDaemon
|
136
|
+
queue: daemons
|
137
|
+
description: "This job will check Daemon every 30 seconds after 120 seconds after start"
|
138
|
+
```
|
129
139
|
|
130
140
|
|
131
141
|
NOTE: Six parameter cron's are also supported (as they supported by
|
132
142
|
rufus-scheduler which powers the sidekiq-scheduler process). This allows you
|
133
|
-
to schedule jobs per second (ie:
|
143
|
+
to schedule jobs per second (ie: `30 * * * * *` would fire a job every 30
|
134
144
|
seconds past the minute).
|
135
145
|
|
136
146
|
A big shout out to [rufus-scheduler](http://github.com/jmettraux/rufus-scheduler)
|
@@ -139,8 +149,8 @@ for handling the heavy lifting of the actual scheduling engine.
|
|
139
149
|
|
140
150
|
### Loading the schedule
|
141
151
|
|
142
|
-
Let's assume your scheduled jobs are defined in a file called
|
143
|
-
you could create a Rails initializer called
|
152
|
+
Let's assume your scheduled jobs are defined in a file called `config/scheduler.yml` under your Rails project,
|
153
|
+
you could create a Rails initializer called `config/initializers/scheduler.rb` which would load the job definitions:
|
144
154
|
|
145
155
|
```ruby
|
146
156
|
require 'sidekiq/scheduler'
|
@@ -153,7 +163,7 @@ Sidekiq.configure_server do |config|
|
|
153
163
|
end
|
154
164
|
```
|
155
165
|
|
156
|
-
If you
|
166
|
+
If you are running a non Rails project you should add code to load the workers classes before loading the schedule.
|
157
167
|
|
158
168
|
```ruby
|
159
169
|
require 'sidekiq/scheduler'
|
@@ -197,12 +207,14 @@ When `:dynamic` flag is set to `true`, schedule changes are loaded every 5 secon
|
|
197
207
|
|
198
208
|
You can set that flag in the following ways.
|
199
209
|
|
200
|
-
-
|
210
|
+
- YAML configuration:
|
211
|
+
|
201
212
|
```
|
202
213
|
:dynamic: true
|
203
214
|
```
|
204
215
|
|
205
216
|
- Initializer configuration:
|
217
|
+
|
206
218
|
```ruby
|
207
219
|
Sidekiq.configure_server do |config|
|
208
220
|
# ...
|
@@ -216,25 +228,30 @@ end
|
|
216
228
|
|
217
229
|
If `:dynamic` flag is set to false, you have to reload the schedule manually in sidekiq
|
218
230
|
side:
|
231
|
+
|
219
232
|
```ruby
|
220
233
|
Sidekiq::Scheduler.reload_schedule!
|
221
234
|
```
|
222
235
|
|
223
|
-
If the schedule did not exist it
|
236
|
+
If the schedule did not exist it will we created, if it existed it will be updated.
|
224
237
|
|
225
238
|
### Testing
|
226
239
|
|
227
|
-
|
228
|
-
```ruby
|
229
|
-
require 'sidekiq'
|
230
|
-
require 'sidekiq-scheduler'
|
231
|
-
require 'sidekiq-scheduler/test'
|
240
|
+
In your tests you can check that a schedule change has been set you have to:
|
232
241
|
|
233
|
-
|
242
|
+
```ruby
|
243
|
+
require 'sidekiq'
|
244
|
+
require 'sidekiq-scheduler'
|
245
|
+
require 'sidekiq-scheduler/test'
|
234
246
|
|
235
|
-
|
236
|
-
|
237
|
-
|
247
|
+
Sidekiq.set_schedule('some_name', { 'every' => ['1m'], 'class' => 'HardWorker' })
|
248
|
+
|
249
|
+
Sidekiq::Scheduler.schedules
|
250
|
+
# => { 'every' => ['1m'], 'class' => 'HardWorker' }
|
251
|
+
|
252
|
+
Sidekiq::Scheduler.schedules_changed
|
253
|
+
# => ['every']
|
254
|
+
```
|
238
255
|
|
239
256
|
|
240
257
|
### Time zones
|
@@ -244,13 +261,17 @@ rather than the `config.time_zone` specified in Rails.
|
|
244
261
|
|
245
262
|
You can explicitly specify the time zone that rufus-scheduler will use:
|
246
263
|
|
247
|
-
|
264
|
+
``` yaml
|
265
|
+
cron: "30 6 * * 1 Europe/Stockholm"
|
266
|
+
```
|
248
267
|
|
249
268
|
Also note that `config.time_zone` in Rails allows for a shorthand (e.g. "Stockholm")
|
250
269
|
that rufus-scheduler does not accept. If you write code to set the scheduler time zone
|
251
270
|
from the `config.time_zone` value, make sure it's the right format, e.g. with:
|
252
271
|
|
253
|
-
|
272
|
+
``` ruby
|
273
|
+
ActiveSupport::TimeZone.find_tzinfo(Rails.configuration.time_zone).name
|
274
|
+
```
|
254
275
|
|
255
276
|
A future version of sidekiq-scheduler may do this for you.
|
256
277
|
|
@@ -258,7 +279,7 @@ A future version of sidekiq-scheduler may do this for you.
|
|
258
279
|
|
259
280
|
SidekiqScheduler provides an extension to the Sidekiq web interface that adds a Recurring Jobs page.
|
260
281
|
|
261
|
-
To use it, set up the Sidekiq web interface according to the Sidekiq documentation and then add the
|
282
|
+
To use it, set up the Sidekiq web interface according to the Sidekiq documentation and then add the `sidekiq-scheduler/web` require:
|
262
283
|
|
263
284
|
``` ruby
|
264
285
|
require 'sidekiq/web'
|
@@ -269,10 +290,10 @@ require 'sidekiq-scheduler/web'
|
|
269
290
|
|
270
291
|
* Fork the project.
|
271
292
|
* Make your feature addition or bug fix.
|
272
|
-
* Add tests for it. This is important so
|
273
|
-
* Commit, do not mess with
|
274
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself
|
275
|
-
* Send
|
293
|
+
* Add tests for it. This is important so it won't break it in a future version unintentionally.
|
294
|
+
* Commit, do not mess with version, or history.
|
295
|
+
(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)
|
296
|
+
* Send a pull request. Bonus points for topic branches.
|
276
297
|
|
277
298
|
## Credits
|
278
299
|
|
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.
|
4
|
+
version: 2.0.8
|
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: 2016-
|
12
|
+
date: 2016-07-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sidekiq
|
@@ -169,16 +169,16 @@ dependencies:
|
|
169
169
|
name: activejob
|
170
170
|
requirement: !ruby/object:Gem::Requirement
|
171
171
|
requirements:
|
172
|
-
- - "
|
172
|
+
- - "<"
|
173
173
|
- !ruby/object:Gem::Version
|
174
|
-
version: '
|
174
|
+
version: '5'
|
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
|
-
version: '
|
181
|
+
version: '5'
|
182
182
|
- !ruby/object:Gem::Dependency
|
183
183
|
name: coveralls
|
184
184
|
requirement: !ruby/object:Gem::Requirement
|