sidekiq-scheduler 1.2.4 → 2.0.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: 913d0a502c80f79cdca4bc85a596045107d8f832
4
- data.tar.gz: 29b8f1d878f48f8ac2c76247f5bfe32c8f81d4c9
3
+ metadata.gz: 037b6a4d410e4524dbf981cc073d9c30c5e31009
4
+ data.tar.gz: 345305609e9b89c755d636c6c9124090be88c777
5
5
  SHA512:
6
- metadata.gz: 1facd7ab31fad6ef51c970ec935c14dda672844bf4ef47443750e1f0892e04cb0fd35e7a491468d836f121f49e18ef033f07e5dee32f41e111a216040d36de09
7
- data.tar.gz: 74fd5650d26acfd341ad425cb3ba95eee3cc5001d2c9d852d91c6ee6a318806250c206ec9fd55046390a04977643b30960fe295f9617bcbc69332a64832e5518
6
+ metadata.gz: f4581a66f03bd8c574565f3ea432fc5a179a1a3e28fd3d93c0822f320b36369415c2cb84945599772631b9b4c4828f3f4f8b011144c7ecf516cb4546020066b1
7
+ data.tar.gz: 582260da864b28b3f9cf0484012e1356dad92253732f1c404cf2b3fb2971563ed8bc87b9d728848e5e6f80a3fa18e50c8e1a67c87d75cb627f4864f050ca46a0
data/README.md CHANGED
@@ -167,6 +167,32 @@ Run `spring stop` to stop Spring.
167
167
 
168
168
  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).
169
169
 
170
+ ### Reloading the schedules
171
+
172
+ The schedules can we updated from redis, every 5 seconds the redis is checked for schedule changes,
173
+ to update an schedule you have to:
174
+
175
+ ```ruby
176
+ Sidekiq.set_schedule('some_name', { 'every' => ['1m'], 'class' => 'HardWorker' })
177
+ ```
178
+
179
+ If the schedule did not exist it'll we created if it existed it'll be updated
180
+
181
+ ### Testing
182
+
183
+ In your tests you can check that a schedule change has been set you have to:
184
+ ```ruby
185
+ require 'sidekiq'
186
+ require 'sidekiq-scheduler'
187
+ require 'sidekiq-scheduler/test'
188
+
189
+ Sidekiq.set_schedule('some_name', { 'every' => ['1m'], 'class' => 'HardWorker' })
190
+
191
+ Sidekiq::Scheduler.schedules => { 'every' => ['1m'], 'class' => 'HardWorker' }
192
+ Sidekiq::Scheduler.schedules_changed => ['every']
193
+ ```
194
+
195
+
170
196
  ### Time zones
171
197
 
172
198
  Note that if you use the cron syntax, this will be interpreted as in the server time zone
@@ -1,4 +1,5 @@
1
1
  require 'sidekiq'
2
+ require 'tilt/erb'
2
3
 
3
4
  require_relative 'sidekiq-scheduler/version'
4
5
  require_relative 'sidekiq-scheduler/manager'
@@ -23,4 +24,3 @@ Sidekiq.configure_server do |config|
23
24
  end
24
25
 
25
26
  end
26
-
@@ -1,4 +1,3 @@
1
- require 'celluloid'
2
1
  require 'redis'
3
2
 
4
3
  require 'sidekiq/util'
@@ -14,28 +13,19 @@ module SidekiqScheduler
14
13
  #
15
14
  class Manager
16
15
  include Sidekiq::Util
17
- include Celluloid
18
-
19
- def initialize(options={})
20
- @enabled = options[:scheduler]
21
16
 
17
+ def initialize(options)
22
18
  Sidekiq::Scheduler.enabled = options[:enabled]
23
- Sidekiq::Scheduler.dynamic = options[:dynamic] || false
19
+ Sidekiq::Scheduler.dynamic = options[:dynamic]
24
20
  Sidekiq.schedule = options[:schedule] if options[:schedule]
25
21
  end
26
22
 
27
23
  def stop
28
- @enabled = false
24
+ Sidekiq::Scheduler.clear_schedule!
29
25
  end
30
26
 
31
27
  def start
32
- # Load the schedule into rufus
33
- # If dynamic is set, load that schedule otherwise use normal load
34
- if @enabled && Sidekiq::Scheduler.dynamic && Sidekiq::Scheduler.enabled
35
- Sidekiq::Scheduler.reload_schedule!
36
- elsif @enabled && Sidekiq::Scheduler.enabled
37
- Sidekiq::Scheduler.load_schedule!
38
- end
28
+ Sidekiq::Scheduler.load_schedule!
39
29
  end
40
30
 
41
31
  def reset
@@ -44,4 +34,4 @@ module SidekiqScheduler
44
34
 
45
35
  end
46
36
 
47
- end
37
+ end
@@ -1,5 +1,5 @@
1
1
  module SidekiqScheduler
2
2
 
3
- VERSION = '1.2.4'
3
+ VERSION = '2.0.0'
4
4
 
5
5
  end
@@ -6,7 +6,7 @@ module SidekiqScheduler
6
6
 
7
7
  def self.registered(app)
8
8
  app.get '/recurring-jobs' do
9
- @schedule = Sidekiq.schedule!
9
+ @schedule = (Sidekiq.schedule! || [])
10
10
 
11
11
  erb File.read(File.join(VIEW_PATH, 'recurring_jobs.erb'))
12
12
  end
@@ -45,8 +45,13 @@ module Sidekiq
45
45
  if enabled
46
46
  logger.info 'Loading Schedule'
47
47
 
48
- # Need to load the schedule from redis for the first time if dynamic
49
- Sidekiq.reload_schedule! if dynamic
48
+ # Load schedule from redis for the first time if dynamic
49
+ if dynamic
50
+ Sidekiq.reload_schedule!
51
+ self.rufus_scheduler.every('5s') do
52
+ self.update_schedule
53
+ end
54
+ end
50
55
 
51
56
  logger.info 'Schedule empty! Set Sidekiq.schedule' if Sidekiq.schedule.empty?
52
57
 
@@ -131,6 +131,40 @@ class ManagerTest < Minitest::Test
131
131
  assert_equal '/tmp/2', Sidekiq.schedule['some_ivar_job2']['args']
132
132
  end
133
133
 
134
+ it 'reloads the schedule from redis after 5 seconds when dynamic' do
135
+ Sidekiq.redis { |r| r.flushdb }
136
+ Sidekiq::Scheduler.clear_schedule!
137
+
138
+ Sidekiq::Scheduler.dynamic = true
139
+ Sidekiq.schedule = {
140
+ :some_ivar_job => {
141
+ 'cron' => '* * * * *',
142
+ 'class' => 'SomeIvarJob',
143
+ 'args' => '/tmp'
144
+ }
145
+ }
146
+
147
+ Sidekiq::Scheduler.load_schedule!
148
+
149
+ assert Sidekiq::Scheduler.scheduled_jobs.include?('some_ivar_job')
150
+ assert !Sidekiq::Scheduler.scheduled_jobs.include?('some_ivar_job2')
151
+
152
+ Sidekiq.set_schedule(
153
+ 'some_ivar_job2',
154
+ {
155
+ 'cron' => '* * * * *',
156
+ 'class' => 'SomeIvarJob',
157
+ 'args' => '/tmp/2'
158
+ }
159
+ )
160
+
161
+ sleep(7)
162
+
163
+ assert Sidekiq::Scheduler.scheduled_jobs.include?('some_ivar_job')
164
+ assert Sidekiq::Scheduler.scheduled_jobs.include?('some_ivar_job2')
165
+ end
166
+
167
+
134
168
  it 'load_schedule_job loads a schedule' do
135
169
  Sidekiq::Scheduler.load_schedule_job(
136
170
  'some_ivar_job',
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: 1.2.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morton Jonuschat
@@ -9,20 +9,20 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-11 00:00:00.000000000 Z
12
+ date: 2015-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '3'
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'
28
28
  - !ruby/object:Gem::Dependency
@@ -205,7 +205,6 @@ files:
205
205
  - README.md
206
206
  - Rakefile
207
207
  - lib/sidekiq-scheduler.rb
208
- - lib/sidekiq-scheduler/capistrano.rb
209
208
  - lib/sidekiq-scheduler/manager.rb
210
209
  - lib/sidekiq-scheduler/schedule.rb
211
210
  - lib/sidekiq-scheduler/version.rb
@@ -1,54 +0,0 @@
1
- Capistrano::Configuration.instance.load do
2
- before 'deploy', 'sidekiq_scheduler:quiet'
3
- after 'deploy:stop', 'sidekiq_scheduler:stop'
4
- after 'deploy:start', 'sidekiq_scheduler:start'
5
- after 'deploy:restart', 'sidekiq_scheduler:restart'
6
-
7
- _cset(:sidekiq_timeout) { 10 }
8
- _cset(:sidekiq_role) { :app }
9
-
10
- namespace :sidekiq_scheduler do
11
-
12
- desc 'Quiet sidekiq-scheduler with sidekiq (stop accepting new work)'
13
- task :quiet, roles: lambda { fetch(:sidekiq_role) } do
14
- bundle_cmd = fetch(:bundle_cmd, 'bundle')
15
- pid_file = "#{current_path}/tmp/pids/sidekiq.pid"
16
- quiet_cmd = "#{bundle_cmd} exec sidekiqctl quiet #{pid_file}"
17
-
18
- run "cd #{current_path} && if [ -f #{pid_file} ]; then #{quiet_cmd} ; fi"
19
- end
20
-
21
- desc 'Stop sidekiq-scheduler with sidekiq'
22
- task :stop, roles: lambda { fetch(:sidekiq_role) } do
23
- bundle_cmd = fetch(:bundle_cmd, 'bundle')
24
- pid_file = "#{current_path}/tmp/pids/sidekiq.pid"
25
- timeout = fetch(:sidekiq_timeout)
26
- stop_cmd = "#{bundle_cmd} exec sidekiqctl stop #{pid_file} #{timeout}"
27
-
28
- run "cd #{current_path} && if [ -f #{pid_file} ]; then #{stop_cmd} ; fi"
29
- end
30
-
31
- desc 'Start sidekiq-scheduler with sidekiq'
32
- task :start, roles: lambda { fetch(:sidekiq_role) } do
33
- rails_env = fetch(:rails_env, 'production')
34
- bundle_cmd = fetch(:bundle_cmd, 'bundle')
35
- log_file = "#{current_path}/log/sidekiq.log 2>&1 &"
36
- pid_file = "#{current_path}/tmp/pids/sidekiq.pid"
37
- start_cmd = "#{bundle_cmd} exec sidekiq-scheduler start "
38
- start_cmd += "-e #{rails_env} "
39
- start_cmd += "-C #{current_path}/config/sidekiq.yml "
40
- start_cmd += "-P #{pid_file} "
41
- exec_cmd = "nohup #{start_cmd}"
42
-
43
- run "cd #{current_path} ; nohup #{exec_cmd} >> #{log_file}", pty: false
44
- end
45
-
46
- desc 'Restart sidekiq-scheduler with sidekiq'
47
- task :restart, roles: lambda { fetch(:sidekiq_role) } do
48
- stop
49
- start
50
- end
51
-
52
- end
53
- end
54
-