chronic_cron 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -1
- data.tar.gz.sig +0 -0
- data/lib/chronic_cron.rb +32 -148
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b2ee2e57788dd1ce049bc000c191b52e1f3ec10
|
4
|
+
data.tar.gz: 53956301fc4972129722a3224af01b703d98bd21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 035ff581044f8cf789307764454c229a5cb60d5a1c6f867665b623abd31166d1fc3675cafc32be7804c71e6379711f3df79a6e5362f6ac6dec9ea598b1c24bd9
|
7
|
+
data.tar.gz: 207f6cf8aafd205b36f6de811b67b06b9700fe3527898d090a7591c87b4ade46e75e69ee69774db8afdbb336029346cdd04454e789a22162a2e2cccfb6fa174b
|
checksums.yaml.gz.sig
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
��x��9N�f�zIO2$mL��2�|⇣�t�t�"f�wa��?DV:�N[���j�ZL�Fs)�'�M��q�47G�����*ܤ:�/)�>- $��$����mfK�J�2��5��y��y�9�n�;���l*�
|
2
|
+
��q>��D��uގ���[q5�0���4]܋�U�n�V"�b1�0�В�b�:��$]$����S��:A\j��Ta��v�_K�AL�ҟ, ���p�F���X��1�#��Y�j���
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/chronic_cron.rb
CHANGED
@@ -2,167 +2,51 @@
|
|
2
2
|
|
3
3
|
# file: chronic_cron.rb
|
4
4
|
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
|
8
|
-
MINUTE = 60
|
9
|
-
HOUR = MINUTE * 60
|
10
|
-
DAY = HOUR * 24
|
11
|
-
|
12
|
-
class Array
|
13
|
-
|
14
|
-
def inflate()
|
15
|
-
Array.new(self.max_by {|x| x.length}.length).map do |x|
|
16
|
-
self.map{|x| x.length <= 1 ? x.first : x.shift}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
5
|
+
require 'app-routes'
|
6
|
+
require 'cron_format'
|
20
7
|
|
21
8
|
|
22
9
|
class ChronicCron
|
10
|
+
include AppRoutes
|
11
|
+
|
12
|
+
attr_reader :to_expression
|
23
13
|
|
24
|
-
def self.
|
25
|
-
|
26
|
-
|
27
|
-
day.to_i <= last_day.day
|
28
|
-
end
|
14
|
+
def self.parse(s, now=Time.now)
|
15
|
+
CronFormat.new(s, now).to_time
|
16
|
+
end
|
29
17
|
|
30
|
-
def
|
18
|
+
def initialize(s, now=Time.now)
|
19
|
+
@now = now
|
20
|
+
super()
|
21
|
+
@params = {}
|
22
|
+
expressions(@params)
|
23
|
+
@to_expression = find_expression s
|
24
|
+
@cf = CronFormat.new(@to_expression, now)
|
25
|
+
end
|
26
|
+
|
27
|
+
def next() @cf.next end
|
28
|
+
def to_time() @cf.to_time end
|
31
29
|
|
32
|
-
|
33
|
-
raw_a << '*' if raw_a.length <= 5 # add the year?
|
34
|
-
|
35
|
-
units = now.to_a.values_at(1..4) + [nil, now.year]
|
36
|
-
|
37
|
-
procs = {
|
38
|
-
min: lambda{|x, interval| x += (interval * MINUTE).to_i},
|
39
|
-
hour: lambda{|x, interval| x += (interval * HOUR).to_i},
|
40
|
-
day: lambda{|x, interval| x += (interval * DAY).to_i},
|
41
|
-
month: lambda{|x, interval|
|
42
|
-
date = x.to_a.values_at(1..5)
|
43
|
-
interval.times { date[3].succ! }
|
44
|
-
Time.parse("%s-%s-%s %s:%s" % date.reverse)},
|
45
|
-
year: lambda{|x, interval|
|
46
|
-
date = x.to_a.values_at(1..5)
|
47
|
-
interval.times { date[4].succ! }
|
48
|
-
Time.parse("%s-%s-%s %s:%s" % date.reverse)}
|
49
|
-
}
|
30
|
+
protected
|
50
31
|
|
51
|
-
|
52
|
-
# convert * to time unit
|
53
|
-
lambda do |x| v2 = x.sub('*', start.to_s)
|
54
|
-
# split any times
|
55
|
-
multiples = v2.split(/,/)
|
56
|
-
range = multiples.map do |time|
|
57
|
-
s1, s2 = time.split(/-/)
|
58
|
-
s2 ? (s1..s2).to_a : s1
|
59
|
-
end
|
60
|
-
range.flatten
|
61
|
-
end
|
32
|
+
def expressions(params)
|
62
33
|
|
34
|
+
get /10:15am every day/ do
|
35
|
+
'0 15 10 * *'
|
63
36
|
end
|
64
|
-
|
65
|
-
# take any repeater out of the unit value
|
66
|
-
raw_units, repeaters = [], []
|
67
37
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
repeaters << v2
|
38
|
+
# e.g. 10:15am every day
|
39
|
+
get /(\d{1,2}):(\d{1,2})am every day/ do |hrs, mins|
|
40
|
+
"0 %s %s * *" % [mins, hrs]
|
72
41
|
end
|
73
42
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
ceil = {min: MINUTE, hour: 23, day: 31, month: 12}.values
|
79
|
-
|
80
|
-
if repeaters.any? then
|
81
|
-
repeaters.each_with_index do |x,i|
|
82
|
-
if x and not raw_a[i][/^\*/] then
|
83
|
-
raw_date[i] = raw_date[i].map {|y|
|
84
|
-
(y.to_i...ceil[i]).step(x.to_i).to_a.map(&:to_s)
|
85
|
-
}.flatten
|
86
|
-
else
|
87
|
-
raw_date[i]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
dates = raw_date.inflate
|
93
|
-
|
94
|
-
a = dates.map do |date|
|
95
|
-
d = date.map{|x| x ? x.clone : nil}
|
96
|
-
wday, year = d.pop(2)
|
97
|
-
d << year
|
98
|
-
|
99
|
-
next unless day_valid? d.reverse.take 3
|
100
|
-
t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
|
101
|
-
|
102
|
-
if t < now and wday and wday != t.wday then
|
103
|
-
d[2], d[3] = now.to_a.values_at(3,4).map(&:to_s)
|
104
|
-
t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
|
105
|
-
t += DAY until t.wday == wday.to_i
|
106
|
-
end
|
107
|
-
|
108
|
-
i = 3
|
109
|
-
while t < now and i >= 0 and raw_a[i][/\*/]
|
110
|
-
d[i] = now.to_a[i+1].to_s
|
111
|
-
t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
|
112
|
-
i -= 1
|
113
|
-
end
|
114
|
-
|
115
|
-
if t < now then
|
116
|
-
|
117
|
-
if t.month < now.month and raw_a[4] == '*' then
|
118
|
-
# increment the year
|
119
|
-
d[4].succ!
|
120
|
-
t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
|
121
|
-
|
122
|
-
if repeaters[4] then
|
123
|
-
d[4].succ!
|
124
|
-
t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
|
125
|
-
end
|
126
|
-
elsif t.day < now.day and raw_a[3] == '*' then
|
127
|
-
# increment the month
|
128
|
-
if d[3].to_i <= 11 then
|
129
|
-
d[3].succ!
|
130
|
-
else
|
131
|
-
d[3] = '1'
|
132
|
-
d[4].succ!
|
133
|
-
end
|
134
|
-
t = Time.parse("%s-%s-%s %s:%s" % d.reverse)
|
135
|
-
elsif t.hour < now.hour and raw_a[2] == '*' then
|
136
|
-
# increment the day
|
137
|
-
t += DAY * ((now.day - d[2].to_i) + 1)
|
138
|
-
elsif t.min < now.min and raw_a[1] == '*' then
|
139
|
-
# increment the hour
|
140
|
-
t += HOUR * ((now.hour - d[1].to_i) + 1)
|
141
|
-
elsif raw_a[0] == '*' then
|
142
|
-
# increment the minute
|
143
|
-
t += MINUTE * ((now.min - d[0].to_i) + 1)
|
144
|
-
t = procs.values[i].call(t, repeaters[i].to_i) if repeaters[i]
|
145
|
-
end
|
146
|
-
|
147
|
-
end
|
148
|
-
|
149
|
-
if wday then
|
150
|
-
t += DAY until t.wday == wday.to_i
|
151
|
-
end
|
152
|
-
|
153
|
-
if t <= now and repeaters.any? then
|
154
|
-
|
155
|
-
repeaters.each_with_index do |x,i|
|
156
|
-
if x then
|
157
|
-
t = procs.values[i].call(t, x.to_i)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
t
|
43
|
+
# e.g. at 11:00 and 16:00 on every day
|
44
|
+
get /(\d{1,2}):(\d{1,2}) and (\d{1,2}):(\d{1,2}) on every day/ do
|
45
|
+
"00 %s,%s * * *" % params.captures
|
163
46
|
end
|
164
47
|
|
165
|
-
a.compact.min
|
166
48
|
end
|
167
49
|
|
168
|
-
|
50
|
+
alias find_expression run_route
|
51
|
+
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chronic_cron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
aYYwh4InyS/QZr4LG0nh0TuYVP5vwm1cCSlLlo4dlv7bl7Q4y815j70z8O4oUrT8
|
30
30
|
5oSIzmlVDEDmwAibYqdf+aHqmum1mkYW
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2013-07-
|
32
|
+
date: 2013-07-07 00:00:00.000000000 Z
|
33
33
|
dependencies: []
|
34
34
|
description:
|
35
35
|
email:
|
metadata.gz.sig
CHANGED
Binary file
|