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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 626b3fd7c019919cbc1a8167cdd670403e5a48045494b0f9fcfe1a8bde0c2220
4
- data.tar.gz: 0bce529fc4c6a7f2c014eaebb6c29af4809853ea4320134dd366d47a4a516565
3
+ metadata.gz: 00adf5caab30b5ca768bf2e06cef40bb7e2ffa357348dfcda7913fed92580047
4
+ data.tar.gz: 525862ca3e6c6e2227b32d62454b9c45f2ac77c5a6529b09911a6bf83f140e47
5
5
  SHA512:
6
- metadata.gz: 6ac01a43b6ea171584190277db65449ee49df52d8eab18ad6029cc6468f3589100f22ca4dbce8b4fa6062708b99983ab28ffac0004c4c4956dfa2b25405b73b7
7
- data.tar.gz: 3030ce6d64673952b83d6b904f46e31263b36181b90471f4a584188474fdbdcf01fc301580fcc1a9c08794b1a20629eb03fa9f2bae2a048cdb21c0bfb22dc560
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
- SECONDS_PER_HOUR = 60 * 60
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
- # figure out how many times job will happen in a day
58
- runs_per_day = SECONDS_PER_DAY / interval
58
+ job_offset = offset(job_identifier, interval: interval)
59
59
 
60
- run_at = Time.at(offset(job_identifier, interval: interval)).utc
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
- hours = []
63
- runs_per_day.times do |i|
64
- hours << run_at.hour + (i * interval / SECONDS_PER_HOUR)
65
- end
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
- "#{run_at.min} #{hours.join(',')} * * *"
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
@@ -1,3 +1,3 @@
1
1
  module CronSwanson
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
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.1
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
- rubygems_version: 3.0.3
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