cron_config_parser 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +11 -4
- data/lib/cron_config_parser.rb +33 -35
- data/lib/cron_config_parser/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db6d213a9e546d2a205cfa9d33d8379d6ebdd700e57ed92223849df51617dd00
|
4
|
+
data.tar.gz: 617ad627ff951edb6dd964856ef0ad52046059f302de8acf8b87d1d3044c3349
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 368313c9f355a836757b1052bf5e44c39af15ce0aba840e5912ddacba24d69bc21819438d5de1475f9c5da69713e203d12820a83da54d9e1ccedb485badf8530
|
7
|
+
data.tar.gz: 64b590e2b6cfa54dd8c742471705cfa461792d92ed2c2c8090289599961ed0b247c5d41113f23930d4e98db1b24461776815f323bd55e4fe156980d0eecd2e61
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -32,7 +32,7 @@ CronConfigParser.call('00 5 * * * Asia/Tokyo')
|
|
32
32
|
@wdays=["*"]>
|
33
33
|
```
|
34
34
|
|
35
|
-
|
35
|
+
You can check configured properties.
|
36
36
|
|
37
37
|
``` ruby
|
38
38
|
# return false if configured nil or '*'
|
@@ -43,20 +43,21 @@ config.days_configured?
|
|
43
43
|
=> false
|
44
44
|
```
|
45
45
|
|
46
|
-
|
46
|
+
You can check next execute time.
|
47
47
|
|
48
48
|
``` ruby
|
49
49
|
config = CronConfigParser.call('00 5 * * * Asia/Tokyo')
|
50
50
|
config.next_execute_at
|
51
51
|
=> 2019-05-23 05:00:00 +0900
|
52
|
-
|
52
|
+
|
53
|
+
# You can check execute schedule in future by execute_schedule.
|
54
|
+
config.execute_schedule(execute_count: 5, annotation: 'DailyJob')
|
53
55
|
=>
|
54
56
|
[{:annotation=>"DailyJob", :execute_at=>2019-05-23 05:00:00 +0900},
|
55
57
|
{:annotation=>"DailyJob", :execute_at=>2019-05-24 05:00:00 +0900},
|
56
58
|
{:annotation=>"DailyJob", :execute_at=>2019-05-25 05:00:00 +0900},
|
57
59
|
{:annotation=>"DailyJob", :execute_at=>2019-05-26 05:00:00 +0900},
|
58
60
|
{:annotation=>"DailyJob", :execute_at=>2019-05-27 05:00:00 +0900}]
|
59
|
-
=>
|
60
61
|
```
|
61
62
|
|
62
63
|
This gem check simple validation when CronConfigParser::CronConfig object initialize.
|
@@ -82,6 +83,12 @@ CronConfigParser.call('00 5,a * * * Asia/Tokyo', validation: false)
|
|
82
83
|
@wdays=["*"]>
|
83
84
|
```
|
84
85
|
|
86
|
+
## Code Status
|
87
|
+
|
88
|
+
[](https://badge.fury.io/rb/cron_config_parser)
|
89
|
+
|
90
|
+
[](https://travis-ci.com/Madogiwa0124/cron_config_parser)
|
91
|
+
|
85
92
|
## Contributing
|
86
93
|
|
87
94
|
Bug reports and pull requests are welcome on GitHub at https://github.com/Madogiwa0124/cron_config_parser. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/lib/cron_config_parser.rb
CHANGED
@@ -134,15 +134,31 @@ module CronConfigParser
|
|
134
134
|
|
135
135
|
def call
|
136
136
|
next_minute
|
137
|
+
return execute_at if returnable?
|
137
138
|
next_hour
|
139
|
+
return execute_at if returnable?
|
138
140
|
next_day
|
141
|
+
return execute_at if returnable?
|
139
142
|
next_wday
|
143
|
+
return execute_at if returnable?
|
140
144
|
next_month
|
141
145
|
execute_at
|
142
146
|
end
|
143
147
|
|
144
148
|
private
|
145
149
|
|
150
|
+
# check calculated next execution date by below conditions
|
151
|
+
# 1.execute_at is future.(remove default add 1 minutes)
|
152
|
+
# 2.propaty is not configured or propaty include configured values.
|
153
|
+
def returnable?
|
154
|
+
execute_at.ago(1.minute) > basis_datetime \
|
155
|
+
&& (!cron_config.minutes_configured? || cron_config.minutes.include?(execute_at.min)) \
|
156
|
+
&& (!cron_config.hours_configured? || cron_config.hours.include?(execute_at.hour)) \
|
157
|
+
&& (!cron_config.days_configured? || cron_config.days.include?(execute_at.day)) \
|
158
|
+
&& (!cron_config.wdays_configured? || cron_config.wdays.include?(execute_at.wday)) \
|
159
|
+
&& (!cron_config.months_configured? || cron_config.months.include?(execute_at.month))
|
160
|
+
end
|
161
|
+
|
146
162
|
def prepare_cron_config
|
147
163
|
@cron_config.minutes = parse_config_property(:minutes)
|
148
164
|
@cron_config.hours = parse_config_property(:hours)
|
@@ -156,11 +172,13 @@ module CronConfigParser
|
|
156
172
|
end
|
157
173
|
|
158
174
|
def parse_config_property(property_sym)
|
159
|
-
cron_config.send(property_sym).map do |property|
|
175
|
+
result = cron_config.send(property_sym).map do |property|
|
160
176
|
next to_i(property) unless property.match?(/\/|-/)
|
161
177
|
next parse_for_devided_config(property, property_sym) if property.include?('/')
|
162
178
|
next parse_for_range_config(property) if property.include?('-')
|
163
179
|
end.flatten.uniq.sort
|
180
|
+
result.delete(60)
|
181
|
+
result
|
164
182
|
end
|
165
183
|
|
166
184
|
def parse_for_devided_config(property, property_sym)
|
@@ -181,62 +199,42 @@ module CronConfigParser
|
|
181
199
|
|
182
200
|
def next_hour
|
183
201
|
return unless cron_config.hours_configured?
|
184
|
-
# reset hour if configured cron hour
|
185
|
-
@execute_at = @execute_at.change(hour: basis_datetime.hour) if @execute_at.hour >= basis_datetime.hour
|
186
202
|
next_hour = cron_config.hours.select { |config_hour| config_hour > execute_at.hour }.first
|
187
203
|
check_hash = { hour: next_hour.presence || cron_config.hours[0], min: execute_at.min }
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
# reset minute when execute in freture and not configured minute
|
192
|
-
@execute_at = @execute_at.change(min: 0) unless cron_config.minutes_configured?
|
193
|
-
end
|
204
|
+
@execute_at = change_to_property_and_move_up(property: next_hour, property_sym: :hours)
|
205
|
+
# reset minute when execute in freture and not configured minute
|
206
|
+
reset_execute_at(min: 0)
|
194
207
|
end
|
195
208
|
|
196
209
|
def next_day
|
197
210
|
return unless cron_config.days_configured?
|
198
|
-
# reset hour if configured cron hour
|
199
|
-
@execute_at = @execute_at.change(hour: basis_datetime.hour) if @execute_at.hour >= basis_datetime.hour
|
200
211
|
next_day = cron_config.days.select { |config_day| config_day >= execute_at.day }.first
|
201
|
-
|
202
|
-
#
|
203
|
-
|
204
|
-
@execute_at = change_to_property_and_move_up(property: next_day, property_sym: :days)
|
205
|
-
# reset minute when execute in freture and not configured minute, hour
|
206
|
-
@execute_at = @execute_at.change(min: 0) unless cron_config.minutes_configured?
|
207
|
-
@execute_at = @execute_at.change(hour: 0) unless cron_config.minutes_configured?
|
208
|
-
end
|
212
|
+
@execute_at = change_to_property_and_move_up(property: next_day, property_sym: :days)
|
213
|
+
# reset minute when execute in freture and not configured minute, hour
|
214
|
+
reset_execute_at(min: 0, hour: 0)
|
209
215
|
end
|
210
216
|
|
211
217
|
def next_wday
|
212
218
|
return unless cron_config.wdays_configured?
|
213
|
-
@execute_at = @execute_at.change(hour: basis_datetime.hour) if @execute_at.hour >= basis_datetime.hour
|
214
219
|
next_wday = cron_config.wdays.select { |config_wday| config_wday > execute_at.wday }.first
|
215
220
|
next_wday_sym = next_wday ? WDAYS[next_wday] : WDAYS[cron_config.wdays.first]
|
216
221
|
@execute_at = execute_at.next_occurring(next_wday_sym)
|
217
222
|
# reset minute when execute in freture and not configured minute, hour
|
218
|
-
|
219
|
-
@execute_at = @execute_at.change(hour: 0) unless cron_config.minutes_configured?
|
223
|
+
reset_execute_at(min: 0, hour: 0)
|
220
224
|
end
|
221
225
|
|
222
226
|
def next_month
|
223
227
|
return unless cron_config.months_configured?
|
224
|
-
@execute_at = @execute_at.change(hour: basis_datetime.hour) if @execute_at.hour >= basis_datetime.hour
|
225
228
|
next_month = cron_config.months.select { |config_month| config_month >= execute_at.month }.first
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
if cron_config.months.exclude?(execute_at.month) || changed_basis_datetime_future?(check_hash)
|
230
|
-
@execute_at = change_to_property_and_move_up(property: next_month, property_sym: :months)
|
231
|
-
# reset minute when execute in freture and not configured minute, hour, day
|
232
|
-
@execute_at = @execute_at.change(min: 0) unless cron_config.minutes_configured?
|
233
|
-
@execute_at = @execute_at.change(hour: 0) unless cron_config.hours_configured?
|
234
|
-
@execute_at = @execute_at.change(day: 1) unless cron_config.days_configured?
|
235
|
-
end
|
229
|
+
@execute_at = change_to_property_and_move_up(property: next_month, property_sym: :months)
|
230
|
+
# reset minute when execute in freture and not configured minute, hour, day
|
231
|
+
reset_execute_at(min: 0, hour: 0, day: 1)
|
236
232
|
end
|
237
233
|
|
238
|
-
def
|
239
|
-
execute_at
|
234
|
+
def reset_execute_at(min: execute_at.min, hour: execute_at.hour, day: execute_at.day)
|
235
|
+
@execute_at = @execute_at.change(min: min) unless cron_config.minutes_configured?
|
236
|
+
@execute_at = @execute_at.change(hour: hour) unless cron_config.hours_configured?
|
237
|
+
@execute_at = @execute_at.change(day: day) unless cron_config.days_configured?
|
240
238
|
end
|
241
239
|
|
242
240
|
def change_to_property_and_move_up(property:, property_sym:)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cron_config_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Madogiwa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|