Class: Protege::Loop::Schedule
- Inherits:
-
Object
- Object
- Protege::Loop::Schedule
- Defined in:
- lib/protege/loop/schedule.rb
Overview
Domain wrapper over a standard 5-field cron expression — the only knob a responsibility's
schedule exposes. Backed by Fugit::Cron so raw cron parsing never scatters through the engine
(the gateway/wrapper convention), and deliberately answers just one question: does a given
minute match? The Loop scheduler ticks every minute, so there is no "next occurrence" maths to do.
The expression is interpreted in the application timezone (+Time.zone+) by pinning Fugit to that zone's IANA name, so "0 9 * * *" means 9am app-time regardless of the host's system clock.
Instance Attribute Summary collapse
-
#expression ⇒ String
readonly
The raw cron expression as given.
Class Method Summary collapse
-
.valid?(expression) ⇒ Boolean
Whether
expressionparses as a valid cron string.
Instance Method Summary collapse
-
#due?(time) ⇒ Boolean
Whether
timefalls on this schedule, at minute granularity. - #initialize(expression) ⇒ void constructor
-
#valid? ⇒ Boolean
True when the expression parsed as valid cron.
Constructor Details
#initialize(expression) ⇒ void
30 31 32 33 |
# File 'lib/protege/loop/schedule.rb', line 30 def initialize(expression) @expression = expression.to_s.strip @cron = Fugit::Cron.parse(zoned(@expression)) end |
Instance Attribute Details
#expression ⇒ String (readonly)
Returns the raw cron expression as given.
26 27 28 |
# File 'lib/protege/loop/schedule.rb', line 26 def expression @expression end |
Class Method Details
.valid?(expression) ⇒ Boolean
Whether expression parses as a valid cron string. Never raises — safe for validations.
20 21 22 |
# File 'lib/protege/loop/schedule.rb', line 20 def valid?(expression) new(expression).valid? end |
Instance Method Details
#due?(time) ⇒ Boolean
Whether time falls on this schedule, at minute granularity. Seconds are zeroed before the
match because a 5-field cron fires at second zero, while the tick runs a few seconds into the
minute.
46 47 48 49 50 |
# File 'lib/protege/loop/schedule.rb', line 46 def due?(time) return false unless valid? @cron.match?(time.change(sec: 0, usec: 0)) end |
#valid? ⇒ Boolean
Returns true when the expression parsed as valid cron.
36 37 38 |
# File 'lib/protege/loop/schedule.rb', line 36 def valid? !@cron.nil? end |