sqeduler 0.3.5 → 0.3.6
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/CHANGES.md +5 -0
- data/README.md +2 -0
- data/lib/sqeduler/service.rb +8 -1
- data/lib/sqeduler/version.rb +1 -1
- data/lib/sqeduler/worker/kill_switch.rb +6 -0
- data/spec/service_spec.rb +34 -0
- data/spec/worker/kill_switch_spec.rb +21 -0
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 999b1300f9f730cc4648c14082aa596a2e16195a
|
|
4
|
+
data.tar.gz: 4922c321fa003eb1657664182fd7320c9d2092a2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1123efb89e5e45441d4c63690d2c1536ff250e9e5722fafce6c9f27cf2741013d0556707608c5f3c6f0cdaab57fc79a2e58e04138b647f722fadbf03603c3c18
|
|
7
|
+
data.tar.gz: d0205b540bbed7c43215fba5b956d8beef3c86d8eecf995da154dd44de1f89b372ac090528fac46b951cffd1fa353e0b7c2d281a43afb1b1ac795b6f12f481e6
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
|
@@ -72,6 +72,8 @@ To use `Sqeduler::Worker` modules:
|
|
|
72
72
|
* You **DO NOT need** to use this gem for starting Sidekiq or Sidekiq::Scheduler (i.e: `Sqeduler::Service.start`)
|
|
73
73
|
* You **DO need** to provide at `config.redis_hash`, and `config.logger` if you don't want to log to `Rails.logger`.
|
|
74
74
|
* This gem creates a separate `ConnectionPool` so that it can create locks for synchronization and store state for disabling/enabling workers.
|
|
75
|
+
* You **DO need** to `include`/`prepend` these modules in the actual working class
|
|
76
|
+
* They will not work if done in a parent class because of the way `prepend` works in conjunction with inheritance.
|
|
75
77
|
|
|
76
78
|
The modules:
|
|
77
79
|
|
data/lib/sqeduler/service.rb
CHANGED
|
@@ -102,7 +102,8 @@ module Sqeduler
|
|
|
102
102
|
redis_pool = if config.redis_pool
|
|
103
103
|
config.redis_pool
|
|
104
104
|
else
|
|
105
|
-
|
|
105
|
+
# Redis requires config hash to have symbols as keys.
|
|
106
|
+
redis = { :namespace => "sqeduler" }.merge(symbolize_keys(config.redis_hash))
|
|
106
107
|
::Sidekiq::RedisConnection.create(redis)
|
|
107
108
|
end
|
|
108
109
|
verify_redis_pool(redis_pool)
|
|
@@ -114,6 +115,12 @@ module Sqeduler
|
|
|
114
115
|
return Rails.logger if defined?(Rails)
|
|
115
116
|
raise ArgumentError, "No logger provided and Rails.logger cannot be inferred"
|
|
116
117
|
end
|
|
118
|
+
|
|
119
|
+
private
|
|
120
|
+
|
|
121
|
+
def symbolize_keys(hash)
|
|
122
|
+
hash.map { |k, v| [k.to_sym, v] }.to_h
|
|
123
|
+
end
|
|
117
124
|
end
|
|
118
125
|
end
|
|
119
126
|
end
|
data/lib/sqeduler/version.rb
CHANGED
|
@@ -12,6 +12,12 @@ module Sqeduler
|
|
|
12
12
|
base.extend(ClassMethods)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
def self.disabled
|
|
16
|
+
Service.redis_pool.with do |redis|
|
|
17
|
+
redis.hgetall(SIDEKIQ_DISABLED_WORKERS)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
15
21
|
# rubocop:disable Style/Documentation
|
|
16
22
|
module ClassMethods
|
|
17
23
|
def enable
|
data/spec/service_spec.rb
CHANGED
|
@@ -171,6 +171,40 @@ RSpec.describe Sqeduler::Service do
|
|
|
171
171
|
expect { described_class.redis_pool }.to raise_error
|
|
172
172
|
end
|
|
173
173
|
end
|
|
174
|
+
|
|
175
|
+
context "when provided redis_hash has strings as keys" do
|
|
176
|
+
let(:expected_redis_config) do
|
|
177
|
+
REDIS_CONFIG.merge(:namespace => "sqeduler")
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
before do
|
|
181
|
+
described_class.config = Sqeduler::Config.new.tap do |config|
|
|
182
|
+
config.redis_hash = REDIS_CONFIG.map { |k, v| [k.to_s, v] }.to_h
|
|
183
|
+
config.logger = logger
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
it "converts keys to symbols to create redis" do
|
|
188
|
+
expect(::Sidekiq::RedisConnection).to receive(:create).with(expected_redis_config).and_call_original
|
|
189
|
+
subject
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
context "with namespace provided in redis_hash" do
|
|
194
|
+
let(:redis_hash) { REDIS_CONFIG.merge(:namespace => "foo") }
|
|
195
|
+
|
|
196
|
+
before do
|
|
197
|
+
described_class.config = Sqeduler::Config.new.tap do |config|
|
|
198
|
+
config.redis_hash = redis_hash
|
|
199
|
+
config.logger = logger
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it "uses the provided namespace" do
|
|
204
|
+
expect(::Sidekiq::RedisConnection).to receive(:create).with(redis_hash).and_call_original
|
|
205
|
+
subject
|
|
206
|
+
end
|
|
207
|
+
end
|
|
174
208
|
end
|
|
175
209
|
|
|
176
210
|
describe ".logger" do
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
require "./spec/fixtures/fake_worker"
|
|
3
|
+
|
|
4
|
+
RSpec.describe Sqeduler::Worker::KillSwitch do
|
|
5
|
+
describe ".disabled" do
|
|
6
|
+
before do
|
|
7
|
+
Sqeduler::Service.config = Sqeduler::Config.new(
|
|
8
|
+
:redis_hash => REDIS_CONFIG,
|
|
9
|
+
:logger => Logger.new(STDOUT).tap { |l| l.level = Logger::DEBUG }
|
|
10
|
+
)
|
|
11
|
+
end
|
|
12
|
+
after { FakeWorker.enable }
|
|
13
|
+
|
|
14
|
+
it "lists the disabled workers" do
|
|
15
|
+
expect(Sqeduler::Worker::KillSwitch.disabled).to eq({})
|
|
16
|
+
time = Time.now
|
|
17
|
+
Timecop.freeze(time) { FakeWorker.disable }
|
|
18
|
+
expect(Sqeduler::Worker::KillSwitch.disabled).to eq("FakeWorker" => time.to_s)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sqeduler
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jared Jenkins
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: sidekiq
|
|
@@ -210,6 +210,7 @@ files:
|
|
|
210
210
|
- spec/spec_helper.rb
|
|
211
211
|
- spec/sqeduler_spec.rb
|
|
212
212
|
- spec/trigger_lock_spec.rb
|
|
213
|
+
- spec/worker/kill_switch_spec.rb
|
|
213
214
|
- spec/worker/synchronization_spec.rb
|
|
214
215
|
- spec/worker_spec.rb
|
|
215
216
|
- sqeduler.gemspec
|
|
@@ -233,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
233
234
|
version: '0'
|
|
234
235
|
requirements: []
|
|
235
236
|
rubyforge_project:
|
|
236
|
-
rubygems_version: 2.4.
|
|
237
|
+
rubygems_version: 2.4.6
|
|
237
238
|
signing_key:
|
|
238
239
|
specification_version: 4
|
|
239
240
|
summary: Common Sidekiq infrastructure for multi-host applications.
|
|
@@ -250,6 +251,7 @@ test_files:
|
|
|
250
251
|
- spec/spec_helper.rb
|
|
251
252
|
- spec/sqeduler_spec.rb
|
|
252
253
|
- spec/trigger_lock_spec.rb
|
|
254
|
+
- spec/worker/kill_switch_spec.rb
|
|
253
255
|
- spec/worker/synchronization_spec.rb
|
|
254
256
|
- spec/worker_spec.rb
|
|
255
257
|
has_rdoc:
|