delayed_cron 0.2.10 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +14 -0
- data/delayed_cron.gemspec +1 -0
- data/lib/delayed_cron.rb +1 -0
- data/lib/delayed_cron/cron_job.rb +3 -3
- data/lib/delayed_cron/version.rb +1 -1
- data/spec/cron_job_spec.rb +32 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98459d8cfb19c18cd7d11fdfa6fd11743dc248cd
|
4
|
+
data.tar.gz: dbd9446e7fcd0f71c98404a4437540b3fdcd225f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b6f2a9a47a0a671a42e2aae7e48929e0a5796949ccbeae7f49ef1d3326dabefe31870ab6e0c263bf355039b1ac4e3763f720ea3591520074807868c920659fb
|
7
|
+
data.tar.gz: 4bbbf3aa5d91f639edd427a66ccf8620c8c3620a8c13a03f902f6a660d8338de6648b222ed4ee42c2f7a7f1276493d2d81b73cb38571a908ff7edcfc0d4ebd0b
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
# 0.2.11
|
2
|
+
|
3
|
+
- Use ActiveSupport::Duration to apply time offsets
|
4
|
+
|
5
|
+
Using seconds to apply the time offsets when the parsed time is in the
|
6
|
+
past is not time zone aware. This causes issues when DST begins/ends
|
7
|
+
between the two times. For example, daily jobs are scheduled an hour
|
8
|
+
earlier than the are supposed to when DST ends since it doesn't take the
|
9
|
+
extra hour into account. This causes further issues when calculating the
|
10
|
+
next offset time, the offset to prevent scheduling past times doesn't
|
11
|
+
apply as expected and the job is scheduled over and over. As a related
|
12
|
+
issue, we sometimes need a two hour jump to bring the parsed time to the
|
13
|
+
future, add a while loop to handle this case.
|
14
|
+
|
1
15
|
# 0.2.10
|
2
16
|
|
3
17
|
- Add ability to set a job time zone and also allow running a job at a specific minute of each hour.
|
data/delayed_cron.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_development_dependency "simplecov"
|
23
23
|
s.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
|
24
24
|
s.add_development_dependency "hashie"
|
25
|
+
s.add_development_dependency "pry-byebug"
|
25
26
|
|
26
27
|
s.files = `git ls-files`.split("\n")
|
27
28
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/delayed_cron.rb
CHANGED
@@ -38,15 +38,15 @@ module DelayedCron
|
|
38
38
|
zone = Time.find_zone!(zone_name)
|
39
39
|
|
40
40
|
if hourly?
|
41
|
-
|
41
|
+
period_duration = 1.hour
|
42
42
|
scheduled_time_string = "%H:#{scheduled_time_string}"
|
43
43
|
else
|
44
|
-
|
44
|
+
period_duration = 1.day
|
45
45
|
end
|
46
46
|
|
47
47
|
scheduled_time = zone.now.strftime("%Y-%m-%d #{scheduled_time_string}")
|
48
48
|
scheduled_time = zone.parse(scheduled_time)
|
49
|
-
scheduled_time +=
|
49
|
+
scheduled_time += period_duration while zone.now >= scheduled_time
|
50
50
|
scheduled_time.to_i - zone.now.to_i
|
51
51
|
end
|
52
52
|
|
data/lib/delayed_cron/version.rb
CHANGED
data/spec/cron_job_spec.rb
CHANGED
@@ -76,8 +76,11 @@ module DelayedCron
|
|
76
76
|
let(:next_occurrence) do
|
77
77
|
job.send(:convert_time_string_to_seconds_interval, scheduled_time, "Eastern Time (US & Canada)")
|
78
78
|
end
|
79
|
+
let(:zone) { Time.find_zone!("Eastern Time (US & Canada)") }
|
80
|
+
|
79
81
|
# Set Time.now to January 1, 2014 12:00:00 PM
|
80
82
|
before { Timecop.freeze(Time.utc(2014, 1, 1, 12, 0, 0)) }
|
83
|
+
|
81
84
|
context "next occurrence is today" do
|
82
85
|
let(:known_interval) { 21600 }
|
83
86
|
let(:scheduled_time) { "13:00:00 -0500" }
|
@@ -132,6 +135,35 @@ module DelayedCron
|
|
132
135
|
|
133
136
|
expect(next_occurrence).to be(known_interval)
|
134
137
|
end
|
138
|
+
|
139
|
+
it 'handles DST end' do
|
140
|
+
time = zone.local(2017, 11, 5, 1, 0) + 1.hour # ST start
|
141
|
+
Timecop.freeze(time)
|
142
|
+
|
143
|
+
expect(next_occurrence).to eq(1.hour.to_i)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'DST ends before next time' do
|
148
|
+
let(:scheduled_time) { "00:05:00" }
|
149
|
+
|
150
|
+
it 'adds an extra hour to the offset' do
|
151
|
+
time = zone.local(2017, 11, 5, 0, 5)
|
152
|
+
Timecop.freeze(time)
|
153
|
+
|
154
|
+
expect(next_occurrence).to eq(25.hours.to_i)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'calculation is on day of DST end' do
|
159
|
+
let(:scheduled_time) { "00:05:00" }
|
160
|
+
|
161
|
+
it 'still calculates correct offset' do
|
162
|
+
time = zone.local(2017, 11, 5, 23, 5)
|
163
|
+
Timecop.freeze(time)
|
164
|
+
|
165
|
+
expect(next_occurrence).to eq(1.hour.to_i)
|
166
|
+
end
|
135
167
|
end
|
136
168
|
|
137
169
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delayed_cron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Grubbs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: delayed_job
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: pry-byebug
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
167
181
|
description: Run your cron jobs with sidekiq, delayed_job, resque, or sucker_punch.
|
168
182
|
email: justin@sellect.com
|
169
183
|
executables: []
|