Class: SidekiqVigil::Alert::Cron
- Inherits:
-
Object
- Object
- SidekiqVigil::Alert::Cron
- Defined in:
- lib/sidekiq_vigil/alert/cron.rb
Defined Under Namespace
Classes: Field
Constant Summary collapse
- FIELD_RANGES =
[ (0..59), (0..23), (1..31), (1..12), (0..7) ].freeze
Instance Method Summary collapse
-
#initialize(expression) ⇒ Cron
constructor
A new instance of Cron.
- #match?(time) ⇒ Boolean
Constructor Details
#initialize(expression) ⇒ Cron
Returns a new instance of Cron.
16 17 18 19 20 21 |
# File 'lib/sidekiq_vigil/alert/cron.rb', line 16 def initialize(expression) fields = expression.to_s.split raise ConfigError, "mute cron must contain five fields" unless fields.length == FIELD_RANGES.length @fields = fields.zip(FIELD_RANGES).map { |field, range| parse_field(field, range) } end |
Instance Method Details
#match?(time) ⇒ Boolean
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sidekiq_vigil/alert/cron.rb', line 23 def match?(time) minute, hour, day, month, weekday = fields fixed_fields = [[minute, time.min], [hour, time.hour], [month, time.month]] return false unless fixed_fields.all? { |field, value| field.values.include?(value) } day_matches = day.values.include?(time.day) weekday_matches = weekday.values.include?(time.wday) return day_matches || weekday_matches unless day.wildcard || weekday.wildcard day_matches && weekday_matches end |