sqeduler 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/.travis.yml +1 -0
- data/CHANGES.md +11 -2
- data/Gemfile +0 -2
- data/Rakefile +2 -0
- data/lib/sqeduler/service.rb +7 -1
- data/lib/sqeduler/trigger_lock.rb +2 -0
- data/lib/sqeduler/version.rb +1 -1
- data/lib/sqeduler/worker/synchronization.rb +1 -1
- data/spec/fixtures/schedule.yaml +1 -1
- data/spec/service_spec.rb +10 -2
- data/spec/trigger_lock_spec.rb +6 -0
- data/spec/worker_spec.rb +36 -35
- data/sqeduler.gemspec +4 -4
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 510d5754df3875e36f052b971668cf58ccdcdde1
|
4
|
+
data.tar.gz: dd0b216fe36b27a4df8f76dbd243e4f088b45fe8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64eb353667433b507b725db2b9b92adc5dde0ec71a140ddc640a5c74a52f42dcbfa1dc63ddeba27b4c8ebd0b188711e5256cac9f89d2edd45cff0f5d635d1e7c
|
7
|
+
data.tar.gz: 1e7cde947da623040ee8f07218fc7b02be92b0c4bec6f54b9688068fc662b090eaadd8f6a3e8466493244aa43ed9e395f552be5443f3dee36bb13a19857c43e0
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
@@ -1,4 +1,13 @@
|
|
1
|
-
### 0.
|
1
|
+
### 0.2.2 / 2015-11-11
|
2
2
|
|
3
|
-
*
|
3
|
+
* Support ERB in job schedules
|
4
|
+
* Handle exceptions more gracefully in lock acquisition
|
4
5
|
|
6
|
+
### 0.2.0 / 2015-04-18
|
7
|
+
|
8
|
+
* Add KillSwitch middleware
|
9
|
+
* Cleanup
|
10
|
+
|
11
|
+
### 0.1.4 / 2015-03-26
|
12
|
+
|
13
|
+
* Initial release
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/lib/sqeduler/service.rb
CHANGED
@@ -73,12 +73,18 @@ module Sqeduler
|
|
73
73
|
::Sidekiq::Scheduler.rufus_scheduler_options = {
|
74
74
|
:trigger_lock => TriggerLock.new
|
75
75
|
}
|
76
|
-
::Sidekiq.schedule =
|
76
|
+
::Sidekiq.schedule = parse_schedule(config.schedule_path)
|
77
77
|
else
|
78
78
|
logger.warn "No schedule_path provided. Not starting Sidekiq::Scheduler."
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
|
+
def parse_schedule(path)
|
83
|
+
fail "Schedule file #{path} does not exist!" unless File.exist?(path)
|
84
|
+
file_contents = File.read(path)
|
85
|
+
YAML.load(ERB.new(file_contents).result)
|
86
|
+
end
|
87
|
+
|
82
88
|
def scheduling?
|
83
89
|
!config.schedule_path.to_s.empty?
|
84
90
|
end
|
data/lib/sqeduler/version.rb
CHANGED
@@ -93,7 +93,7 @@ module Sqeduler
|
|
93
93
|
|
94
94
|
# rubocop:disable Metrics/AbcSize
|
95
95
|
def time_duration(timespan)
|
96
|
-
rest, secs = timespan.divmod(60)
|
96
|
+
rest, secs = timespan.divmod(60) # self is the time difference t2 - t1
|
97
97
|
rest, mins = rest.divmod(60)
|
98
98
|
days, hours = rest.divmod(24)
|
99
99
|
|
data/spec/fixtures/schedule.yaml
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
FakeWorker:
|
2
|
-
every:
|
2
|
+
every: <%=5%>s
|
data/spec/service_spec.rb
CHANGED
@@ -55,7 +55,11 @@ RSpec.describe Sqeduler::Service do
|
|
55
55
|
|
56
56
|
context "a schedule_path is provided" do
|
57
57
|
it "starts the scheduler" do
|
58
|
-
expect(Sidekiq).to receive(:"schedule=").with(
|
58
|
+
expect(Sidekiq).to receive(:"schedule=").with(
|
59
|
+
"FakeWorker" => {
|
60
|
+
"every" => "5s"
|
61
|
+
}
|
62
|
+
)
|
59
63
|
subject
|
60
64
|
expect(Sidekiq::Scheduler.rufus_scheduler_options).to have_key(:trigger_lock)
|
61
65
|
expect(Sidekiq::Scheduler.rufus_scheduler_options[:trigger_lock]).to be_kind_of(
|
@@ -67,7 +71,11 @@ RSpec.describe Sqeduler::Service do
|
|
67
71
|
let(:schedule_filepath) { "./spec/fixtures/schedule.yaml" }
|
68
72
|
|
69
73
|
it "starts the scheduler" do
|
70
|
-
expect(Sidekiq).to receive(:"schedule=").with(
|
74
|
+
expect(Sidekiq).to receive(:"schedule=").with(
|
75
|
+
"FakeWorker" => {
|
76
|
+
"every" => "5s"
|
77
|
+
}
|
78
|
+
)
|
71
79
|
subject
|
72
80
|
expect(Sidekiq::Scheduler.rufus_scheduler_options).to have_key(:trigger_lock)
|
73
81
|
expect(Sidekiq::Scheduler.rufus_scheduler_options[:trigger_lock]).to be_kind_of(
|
data/spec/trigger_lock_spec.rb
CHANGED
@@ -76,5 +76,11 @@ RSpec.describe Sqeduler::TriggerLock do
|
|
76
76
|
expect(trigger_lock_2.locked?).to be(true)
|
77
77
|
expect(trigger_lock_1.unlock).to be(false)
|
78
78
|
end
|
79
|
+
|
80
|
+
it "should not acquire the lock if there is an error" do
|
81
|
+
allow(trigger_lock_1).to receive(:refresh_lock).and_raise("boom")
|
82
|
+
expect(trigger_lock_1.lock).to be false
|
83
|
+
expect(trigger_lock_1.locked?).to be false
|
84
|
+
end
|
79
85
|
end
|
80
86
|
end
|
data/spec/worker_spec.rb
CHANGED
@@ -43,14 +43,15 @@ RSpec.describe Sqeduler::Worker do
|
|
43
43
|
let(:expiration) { work_time * 4 }
|
44
44
|
let(:work_time) { 0.1 }
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
def run_synchronized_workers
|
47
|
+
worker1 = Thread.new do
|
48
|
+
FakeWorker.new.perform(work_time)
|
49
|
+
end
|
50
|
+
worker2 = Thread.new do
|
50
51
|
sleep wait_time
|
51
52
|
FakeWorker.new.perform(work_time)
|
52
53
|
end
|
53
|
-
|
54
|
+
worker1.join && worker2.join
|
54
55
|
end
|
55
56
|
|
56
57
|
context "overlapping schedule" do
|
@@ -60,32 +61,32 @@ RSpec.describe Sqeduler::Worker do
|
|
60
61
|
let(:timeout) { work_time / 2 }
|
61
62
|
|
62
63
|
it "one worker should be blocked" do
|
63
|
-
|
64
|
+
run_synchronized_workers
|
64
65
|
verify_callback_occured(FakeWorker::JOB_LOCK_FAILURE_PATH)
|
65
66
|
end
|
66
67
|
|
67
68
|
it "only one worker should run" do
|
68
|
-
|
69
|
+
run_synchronized_workers
|
69
70
|
verify_callback_occured(FakeWorker::JOB_RUN_PATH)
|
70
71
|
end
|
71
72
|
|
72
73
|
it "one worker should succeed" do
|
73
|
-
|
74
|
+
run_synchronized_workers
|
74
75
|
verify_callback_occured(FakeWorker::JOB_SUCCESS_PATH, 2)
|
75
76
|
end
|
76
77
|
|
77
78
|
it "no worker should fail" do
|
78
|
-
|
79
|
+
run_synchronized_workers
|
79
80
|
verify_callback_skipped(FakeWorker::JOB_FAILURE_PATH)
|
80
81
|
end
|
81
82
|
|
82
83
|
it "all workers should have received before_start" do
|
83
|
-
|
84
|
+
run_synchronized_workers
|
84
85
|
verify_callback_occured(FakeWorker::JOB_BEFORE_START_PATH, 2)
|
85
86
|
end
|
86
87
|
|
87
88
|
it "a schedule collision should not have occurred" do
|
88
|
-
|
89
|
+
run_synchronized_workers
|
89
90
|
verify_callback_skipped(FakeWorker::SCHEDULE_COLLISION_PATH)
|
90
91
|
end
|
91
92
|
end
|
@@ -94,27 +95,27 @@ RSpec.describe Sqeduler::Worker do
|
|
94
95
|
let(:timeout) { work_time * 4 }
|
95
96
|
|
96
97
|
it "no worker should be blocked" do
|
97
|
-
|
98
|
+
run_synchronized_workers
|
98
99
|
verify_callback_skipped(FakeWorker::JOB_LOCK_FAILURE_PATH)
|
99
100
|
end
|
100
101
|
|
101
102
|
it "both workers should succeed" do
|
102
|
-
|
103
|
+
run_synchronized_workers
|
103
104
|
verify_callback_occured(FakeWorker::JOB_SUCCESS_PATH, 2)
|
104
105
|
end
|
105
106
|
|
106
107
|
it "no worker should fail" do
|
107
|
-
|
108
|
+
run_synchronized_workers
|
108
109
|
verify_callback_skipped(FakeWorker::JOB_FAILURE_PATH)
|
109
110
|
end
|
110
111
|
|
111
112
|
it "all workers should have received before_start" do
|
112
|
-
|
113
|
+
run_synchronized_workers
|
113
114
|
verify_callback_occured(FakeWorker::JOB_BEFORE_START_PATH, 2)
|
114
115
|
end
|
115
116
|
|
116
117
|
it "a schedule collision should not have occurred" do
|
117
|
-
|
118
|
+
run_synchronized_workers
|
118
119
|
verify_callback_skipped(FakeWorker::SCHEDULE_COLLISION_PATH)
|
119
120
|
end
|
120
121
|
|
@@ -122,28 +123,28 @@ RSpec.describe Sqeduler::Worker do
|
|
122
123
|
let(:expiration) { work_time / 2 }
|
123
124
|
|
124
125
|
it "no worker should be blocked" do
|
125
|
-
|
126
|
+
run_synchronized_workers
|
126
127
|
verify_callback_skipped(FakeWorker::JOB_LOCK_FAILURE_PATH)
|
127
128
|
end
|
128
129
|
|
129
130
|
it "all workers should run" do
|
130
|
-
|
131
|
+
run_synchronized_workers
|
131
132
|
verify_callback_occured(FakeWorker::JOB_RUN_PATH, 2)
|
132
133
|
end
|
133
134
|
|
134
135
|
it "all workers should have received before_start" do
|
135
|
-
|
136
|
+
run_synchronized_workers
|
136
137
|
verify_callback_occured(FakeWorker::JOB_BEFORE_START_PATH, 2)
|
137
138
|
end
|
138
139
|
|
139
140
|
it "no worker should fail" do
|
140
|
-
|
141
|
+
run_synchronized_workers
|
141
142
|
verify_callback_occured(FakeWorker::JOB_SUCCESS_PATH, 2)
|
142
143
|
verify_callback_skipped(FakeWorker::JOB_FAILURE_PATH)
|
143
144
|
end
|
144
145
|
|
145
146
|
it "a schedule collision should occur" do
|
146
|
-
|
147
|
+
run_synchronized_workers
|
147
148
|
verify_callback_occured(FakeWorker::SCHEDULE_COLLISION_PATH, 2)
|
148
149
|
end
|
149
150
|
end
|
@@ -157,28 +158,28 @@ RSpec.describe Sqeduler::Worker do
|
|
157
158
|
let(:timeout) { work_time }
|
158
159
|
|
159
160
|
it "no workers should be blocked" do
|
160
|
-
|
161
|
+
run_synchronized_workers
|
161
162
|
verify_callback_skipped(FakeWorker::JOB_LOCK_FAILURE_PATH)
|
162
163
|
end
|
163
164
|
|
164
165
|
it "all workers should run" do
|
165
|
-
|
166
|
+
run_synchronized_workers
|
166
167
|
verify_callback_occured(FakeWorker::JOB_RUN_PATH, 2)
|
167
168
|
end
|
168
169
|
|
169
170
|
it "no worker should fail" do
|
170
|
-
|
171
|
+
run_synchronized_workers
|
171
172
|
verify_callback_occured(FakeWorker::JOB_SUCCESS_PATH, 2)
|
172
173
|
verify_callback_skipped(FakeWorker::JOB_FAILURE_PATH)
|
173
174
|
end
|
174
175
|
|
175
176
|
it "all workers should have received before_start" do
|
176
|
-
|
177
|
+
run_synchronized_workers
|
177
178
|
verify_callback_occured(FakeWorker::JOB_BEFORE_START_PATH, 2)
|
178
179
|
end
|
179
180
|
|
180
181
|
it "a schedule collision should not have occurred" do
|
181
|
-
|
182
|
+
run_synchronized_workers
|
182
183
|
verify_callback_skipped(FakeWorker::SCHEDULE_COLLISION_PATH)
|
183
184
|
end
|
184
185
|
end
|
@@ -187,22 +188,22 @@ RSpec.describe Sqeduler::Worker do
|
|
187
188
|
let(:timeout) { work_time * 2 }
|
188
189
|
|
189
190
|
it "no worker should be blocked" do
|
190
|
-
|
191
|
+
run_synchronized_workers
|
191
192
|
verify_callback_skipped(FakeWorker::JOB_LOCK_FAILURE_PATH)
|
192
193
|
end
|
193
194
|
|
194
195
|
it "both workers should succeed" do
|
195
|
-
|
196
|
+
run_synchronized_workers
|
196
197
|
verify_callback_occured(FakeWorker::JOB_SUCCESS_PATH, 2)
|
197
198
|
end
|
198
199
|
|
199
200
|
it "no worker should fail" do
|
200
|
-
|
201
|
+
run_synchronized_workers
|
201
202
|
verify_callback_skipped(FakeWorker::JOB_FAILURE_PATH)
|
202
203
|
end
|
203
204
|
|
204
205
|
it "all workers should have received before_start" do
|
205
|
-
|
206
|
+
run_synchronized_workers
|
206
207
|
verify_callback_occured(FakeWorker::JOB_BEFORE_START_PATH, 2)
|
207
208
|
end
|
208
209
|
|
@@ -210,28 +211,28 @@ RSpec.describe Sqeduler::Worker do
|
|
210
211
|
let(:expiration) { work_time / 2 }
|
211
212
|
|
212
213
|
it "no worker should be blocked" do
|
213
|
-
|
214
|
+
run_synchronized_workers
|
214
215
|
verify_callback_skipped(FakeWorker::JOB_LOCK_FAILURE_PATH)
|
215
216
|
end
|
216
217
|
|
217
218
|
it "all workers should run" do
|
218
|
-
|
219
|
+
run_synchronized_workers
|
219
220
|
verify_callback_occured(FakeWorker::JOB_RUN_PATH, 2)
|
220
221
|
end
|
221
222
|
|
222
223
|
it "all workers should have received before_start" do
|
223
|
-
|
224
|
+
run_synchronized_workers
|
224
225
|
verify_callback_occured(FakeWorker::JOB_BEFORE_START_PATH, 2)
|
225
226
|
end
|
226
227
|
|
227
228
|
it "no worker should fail" do
|
228
|
-
|
229
|
+
run_synchronized_workers
|
229
230
|
verify_callback_occured(FakeWorker::JOB_SUCCESS_PATH, 2)
|
230
231
|
verify_callback_skipped(FakeWorker::JOB_FAILURE_PATH)
|
231
232
|
end
|
232
233
|
|
233
234
|
it "a schedule collision should occur" do
|
234
|
-
|
235
|
+
run_synchronized_workers
|
235
236
|
verify_callback_occured(FakeWorker::SCHEDULE_COLLISION_PATH, 2)
|
236
237
|
end
|
237
238
|
end
|
data/sqeduler.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
multiple hosts. Also provides a convenient abstract class for Sidekiq workers.
|
11
11
|
DESC
|
12
12
|
gem.license = "Apache"
|
13
|
-
gem.authors =
|
13
|
+
gem.authors = ["Jared Jenkins"]
|
14
14
|
gem.email = "jaredjenkins@squareup.com"
|
15
15
|
gem.homepage = "https://rubygems.org/gems/sqeduler"
|
16
16
|
|
@@ -20,13 +20,13 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.require_paths = ["lib"]
|
21
21
|
|
22
22
|
gem.add_runtime_dependency "sidekiq"
|
23
|
-
gem.add_runtime_dependency "sidekiq-scheduler"
|
23
|
+
gem.add_runtime_dependency "sidekiq-scheduler", "~> 1.1"
|
24
24
|
gem.add_runtime_dependency "activesupport"
|
25
25
|
|
26
|
-
gem.add_development_dependency "bundler", "~> 1.
|
26
|
+
gem.add_development_dependency "bundler", "~> 1.10"
|
27
27
|
gem.add_development_dependency "pry", "~> 0"
|
28
28
|
gem.add_development_dependency "rake", "~> 10"
|
29
|
-
gem.add_development_dependency "rspec", "~> 3"
|
29
|
+
gem.add_development_dependency "rspec", "~> 3.3"
|
30
30
|
gem.add_development_dependency "rubocop", "~> 0.24"
|
31
31
|
gem.add_development_dependency "timecop", "~> 0"
|
32
32
|
gem.add_development_dependency "yard", "~> 0"
|
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Jared Jenkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: sidekiq-scheduler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '1.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activesupport
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1.
|
61
|
+
version: '1.10'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1.
|
68
|
+
version: '1.10'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '3'
|
103
|
+
version: '3.3'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '3'
|
110
|
+
version: '3.3'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rubocop
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -216,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
216
216
|
version: '0'
|
217
217
|
requirements: []
|
218
218
|
rubyforge_project:
|
219
|
-
rubygems_version: 2.
|
219
|
+
rubygems_version: 2.5.0
|
220
220
|
signing_key:
|
221
221
|
specification_version: 4
|
222
222
|
summary: Common Sidekiq infrastructure for multi-host applications.
|