cron_swanson 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/cron_swanson.rb +26 -9
- data/lib/cron_swanson/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00adf5caab30b5ca768bf2e06cef40bb7e2ffa357348dfcda7913fed92580047
|
4
|
+
data.tar.gz: 525862ca3e6c6e2227b32d62454b9c45f2ac77c5a6529b09911a6bf83f140e47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e94dd18a3e1c621d10b84a2cc8da6c8579c71bda9b6741f87124a61cf223d667a75f49f797e0a9a91599e696d320e742a206f0f25ca28526d6cd614e4b1ea424
|
7
|
+
data.tar.gz: 80b50fb4c707e225662025aea2e7592c24003933df22fd38af2c5228ec96425ca3ee20b0f545fa3041c37016c25e744a0d9c41d72debc5c7c0c7f3c35b0bded6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.3.2 : "I regret nothing. The end." : November 4, 2019
|
4
|
+
|
5
|
+
Important bugfix: Previous versions would generate invalid schedule strings
|
6
|
+
for intervals less than 1 hour in length.
|
7
|
+
|
3
8
|
## 0.3.0 : "Any dog under 50 pounds is a cat and cats are useless." : November 4, 2019
|
4
9
|
|
5
10
|
New feature:
|
data/lib/cron_swanson.rb
CHANGED
@@ -5,7 +5,8 @@ require 'digest/sha2'
|
|
5
5
|
# CronSwanson is a utility to generate run times for cron jobs which are
|
6
6
|
# regular, but which vary per job.
|
7
7
|
module CronSwanson
|
8
|
-
|
8
|
+
SECONDS_PER_MINUTE = 60
|
9
|
+
SECONDS_PER_HOUR = SECONDS_PER_MINUTE * 60
|
9
10
|
SECONDS_PER_DAY = SECONDS_PER_HOUR * 24
|
10
11
|
|
11
12
|
def self.default_interval
|
@@ -54,16 +55,32 @@ module CronSwanson
|
|
54
55
|
"divisible by the given interval."
|
55
56
|
end
|
56
57
|
|
57
|
-
|
58
|
-
runs_per_day = SECONDS_PER_DAY / interval
|
58
|
+
job_offset = offset(job_identifier, interval: interval)
|
59
59
|
|
60
|
-
|
60
|
+
if interval >= SECONDS_PER_HOUR
|
61
|
+
# figure out how many times job will happen in a day
|
62
|
+
runs_per_day = SECONDS_PER_DAY / interval
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
run_at = Time.at(job_offset).utc
|
65
|
+
hours = []
|
66
|
+
runs_per_day.times do |i|
|
67
|
+
hours << run_at.hour + (i * interval / SECONDS_PER_HOUR)
|
68
|
+
end
|
69
|
+
|
70
|
+
"#{run_at.min} #{hours.join(',')} * * *"
|
71
|
+
else
|
72
|
+
minutes = []
|
73
|
+
|
74
|
+
job_offset_minutes = job_offset / SECONDS_PER_MINUTE
|
75
|
+
interval_minutes = interval / SECONDS_PER_MINUTE
|
66
76
|
|
67
|
-
|
77
|
+
runs_per_hour = SECONDS_PER_HOUR / interval
|
78
|
+
runs_per_hour.times do |i|
|
79
|
+
puts "job_offset:#{job_offset} i:#{i} interval:#{interval}"
|
80
|
+
minutes << job_offset_minutes + (i * interval_minutes)
|
81
|
+
end
|
82
|
+
|
83
|
+
"#{minutes.join(',')} * * * *"
|
84
|
+
end
|
68
85
|
end
|
69
86
|
end
|
data/lib/cron_swanson/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cron_swanson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Dean
|
@@ -83,7 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
|
-
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.7.6.2
|
87
88
|
signing_key:
|
88
89
|
specification_version: 4
|
89
90
|
summary: distribute common cron jobs so they don't all start at the same moment
|