sidekiq-scheduler 2.0.6 → 2.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -8
- data/lib/sidekiq-scheduler/schedule.rb +1 -1
- data/lib/sidekiq-scheduler/version.rb +1 -1
- data/lib/sidekiq/scheduler.rb +63 -6
- data/web/locales/es.yml +9 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d0589167bd1d704cc531881f41ce934e07e684a
|
4
|
+
data.tar.gz: 4a07798d84026cedbb746d6c455463ae796ca56f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56218d97eb155af5fbf07e4ccbca6a5e76bfe5e23facefb8e685758d3f031b17ab6f66ed89132a8953a8b03ad3935132cb1eefedbf3adbb2d23168698c4b959a
|
7
|
+
data.tar.gz: 722247865b66c237efcea76d099207b746e5058adeb60a550a8090baec5c666dab01f7659a8c00d3021fa9138692eccde02b62343980b3da2f9cfab5b2d4a0de
|
data/README.md
CHANGED
@@ -56,7 +56,7 @@ You can add sidekiq-scheduler configuration options to sidekiq.yml config file.
|
|
56
56
|
Available options are:
|
57
57
|
|
58
58
|
:schedule: <the schedule to be run>
|
59
|
-
:dynamic: <if true the schedule can be modified in runtime>
|
59
|
+
:dynamic: <if true the schedule can be modified in runtime [false by default]>
|
60
60
|
:enabled: <enables scheduler if true [true by default]>
|
61
61
|
:scheduler:
|
62
62
|
:listened_queues_only: <push jobs whose queue is being listened by sidekiq [false by default]>
|
@@ -187,16 +187,42 @@ For more information, see [this issue](https://github.com/Moove-it/sidekiq-sched
|
|
187
187
|
|
188
188
|
### Reloading the schedules
|
189
189
|
|
190
|
-
|
191
|
-
to update an schedule you have to:
|
190
|
+
Schedules are stored in Redis. To add / update an schedule, you have to:
|
192
191
|
|
193
|
-
|
194
|
-
|
195
|
-
|
192
|
+
```ruby
|
193
|
+
Sidekiq.set_schedule('heartbeat', { 'every' => ['1m'], 'class' => 'HeartbeatWorker' })
|
194
|
+
```
|
195
|
+
|
196
|
+
When `:dynamic` flag is set to `true`, schedule changes are loaded every 5 seconds.
|
197
|
+
|
198
|
+
You can set that flag in the following ways.
|
199
|
+
|
200
|
+
- Yaml configuration:
|
201
|
+
```
|
202
|
+
:dynamic: true
|
203
|
+
```
|
204
|
+
|
205
|
+
- Initializer configuration:
|
206
|
+
```ruby
|
207
|
+
Sidekiq.configure_server do |config|
|
208
|
+
# ...
|
209
|
+
|
210
|
+
config.on(:startup) do
|
211
|
+
# ...
|
212
|
+
Sidekiq::Scheduler.dynamic = true
|
213
|
+
end
|
214
|
+
end
|
215
|
+
```
|
216
|
+
|
217
|
+
If `:dynamic` flag is set to false, you have to reload the schedule manually in sidekiq
|
218
|
+
side:
|
219
|
+
```ruby
|
220
|
+
Sidekiq::Scheduler.reload_schedule!
|
221
|
+
```
|
196
222
|
|
197
|
-
|
223
|
+
If the schedule did not exist it'll we created, if it existed it'll be updated
|
198
224
|
|
199
|
-
|
225
|
+
### Testing
|
200
226
|
|
201
227
|
In your tests you can check that a schedule change has been set you have to:
|
202
228
|
```ruby
|
@@ -37,7 +37,7 @@ module SidekiqScheduler
|
|
37
37
|
# param, otherwise params is passed in as the only parameter to perform.
|
38
38
|
def schedule=(schedule_hash)
|
39
39
|
schedule_hash = prepare_schedule(schedule_hash)
|
40
|
-
to_remove = (get_all_schedules || {}).keys - schedule_hash.keys
|
40
|
+
to_remove = (get_all_schedules || {}).keys - schedule_hash.keys.map(&:to_s)
|
41
41
|
|
42
42
|
schedule_hash.each do |name, job_spec|
|
43
43
|
set_schedule(name, job_spec)
|
data/lib/sidekiq/scheduler.rb
CHANGED
@@ -7,6 +7,8 @@ module Sidekiq
|
|
7
7
|
class Scheduler
|
8
8
|
extend Sidekiq::Util
|
9
9
|
|
10
|
+
REGISTERED_JOBS_THRESHOLD_IN_SECONDS = 24 * 60 * 60
|
11
|
+
|
10
12
|
# We expect rufus jobs to have #params
|
11
13
|
Rufus::Scheduler::Job.module_eval do
|
12
14
|
|
@@ -100,18 +102,21 @@ module Sidekiq
|
|
100
102
|
if config['rails_env'].nil? || self.rails_env_matches?(config)
|
101
103
|
logger.info "Scheduling #{name} #{config}"
|
102
104
|
interval_defined = false
|
103
|
-
interval_types = %w{cron every at in}
|
105
|
+
interval_types = %w{cron every at in interval}
|
104
106
|
interval_types.each do |interval_type|
|
105
|
-
|
106
|
-
|
107
|
+
config_interval_type = config[interval_type]
|
108
|
+
|
109
|
+
if !config_interval_type.nil? && config_interval_type.length > 0
|
110
|
+
|
111
|
+
args = self.optionizate_interval_value(config_interval_type)
|
107
112
|
|
108
113
|
# We want rufus_scheduler to return a job object, not a job id
|
109
114
|
opts = { :job => true }
|
110
115
|
|
111
|
-
@@scheduled_jobs[name] = self.rufus_scheduler.send(interval_type, *args, opts) do
|
112
|
-
logger.info "queueing #{config['class']} (#{name})"
|
116
|
+
@@scheduled_jobs[name] = self.rufus_scheduler.send(interval_type, *args, opts) do |job, time|
|
113
117
|
config.delete(interval_type)
|
114
|
-
|
118
|
+
|
119
|
+
idempotent_job_enqueue(name, time, config)
|
115
120
|
end
|
116
121
|
|
117
122
|
interval_defined = true
|
@@ -126,6 +131,25 @@ module Sidekiq
|
|
126
131
|
end
|
127
132
|
end
|
128
133
|
|
134
|
+
# Pushes the job into Sidekiq if not already pushed for the given time
|
135
|
+
#
|
136
|
+
# @param [String] job_name The job's name
|
137
|
+
# @param [Time] time The time when the job got cleared for triggering
|
138
|
+
# @param [Hash] config Job's config hash
|
139
|
+
def self.idempotent_job_enqueue(job_name, time, config)
|
140
|
+
registered = register_job_instance(job_name, time)
|
141
|
+
|
142
|
+
if registered
|
143
|
+
logger.info "queueing #{config['class']} (#{job_name})"
|
144
|
+
|
145
|
+
self.handle_errors { self.enqueue_job(config) }
|
146
|
+
|
147
|
+
remove_elder_job_instances(job_name)
|
148
|
+
else
|
149
|
+
logger.debug { "Ignoring #{job_name} job as it has been already enqueued" }
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
129
153
|
# Returns true if the given schedule config hash matches the current
|
130
154
|
# ENV['RAILS_ENV']
|
131
155
|
def self.rails_env_matches?(config)
|
@@ -263,5 +287,38 @@ module Sidekiq
|
|
263
287
|
queues.empty? || queues.include?(job_queue)
|
264
288
|
end
|
265
289
|
|
290
|
+
# Registers a queued job instance
|
291
|
+
#
|
292
|
+
# @param [String] job_name The job's name
|
293
|
+
# @param [Time] time Time at which the job was cleared by the scheduler
|
294
|
+
#
|
295
|
+
# @return [Boolean] true if the job was registered, false when otherwise
|
296
|
+
def self.register_job_instance(job_name, time)
|
297
|
+
pushed_job_key = pushed_job_key(job_name)
|
298
|
+
|
299
|
+
registered, _ = Sidekiq.redis do |r|
|
300
|
+
r.pipelined do
|
301
|
+
r.zadd(pushed_job_key, time.to_i, time.to_i)
|
302
|
+
r.expire(pushed_job_key, REGISTERED_JOBS_THRESHOLD_IN_SECONDS)
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
registered
|
307
|
+
end
|
308
|
+
|
309
|
+
def self.remove_elder_job_instances(job_name)
|
310
|
+
Sidekiq.redis do |r|
|
311
|
+
r.zremrangebyscore(pushed_job_key(job_name), 0, Time.now.to_i - REGISTERED_JOBS_THRESHOLD_IN_SECONDS)
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
# Returns the key of the Redis sorted set used to store job enqueues
|
316
|
+
#
|
317
|
+
# @param [String] job_name The name of the job
|
318
|
+
#
|
319
|
+
# @return [String]
|
320
|
+
def self.pushed_job_key(job_name)
|
321
|
+
"sidekiq-scheduler:pushed:#{job_name}"
|
322
|
+
end
|
266
323
|
end
|
267
324
|
end
|
data/web/locales/es.yml
ADDED
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.7
|
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-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sidekiq
|
@@ -240,6 +240,7 @@ files:
|
|
240
240
|
- lib/sidekiq/scheduler.rb
|
241
241
|
- web/locales/cs.yml
|
242
242
|
- web/locales/en.yml
|
243
|
+
- web/locales/es.yml
|
243
244
|
- web/views/recurring_jobs.erb
|
244
245
|
homepage: https://github.com/moove-it/sidekiq-scheduler
|
245
246
|
licenses:
|
@@ -261,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
261
262
|
version: '0'
|
262
263
|
requirements: []
|
263
264
|
rubyforge_project:
|
264
|
-
rubygems_version: 2.4.5
|
265
|
+
rubygems_version: 2.4.5
|
265
266
|
signing_key:
|
266
267
|
specification_version: 4
|
267
268
|
summary: Light weight job scheduling extension for Sidekiq
|