Class: RoundhouseUi::Recurring::Task
- Inherits:
-
Struct
- Object
- Struct
- RoundhouseUi::Recurring::Task
- Defined in:
- lib/roundhouse_ui/recurring.rb
Instance Attribute Summary collapse
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#last_run ⇒ Object
Returns the value of attribute last_run.
-
#name ⇒ Object
Returns the value of attribute name.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#schedule ⇒ Object
Returns the value of attribute schedule.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#expected_interval ⇒ Object
The interesting question is not "what is the crontab" — it is "this says hourly and has not run in three days".
-
#overdue? ⇒ Boolean
Overdue by more than one whole interval.
- #status ⇒ Object
Instance Attribute Details
#enabled ⇒ Object
Returns the value of attribute enabled
14 15 16 |
# File 'lib/roundhouse_ui/recurring.rb', line 14 def enabled @enabled end |
#klass ⇒ Object
Returns the value of attribute klass
14 15 16 |
# File 'lib/roundhouse_ui/recurring.rb', line 14 def klass @klass end |
#last_run ⇒ Object
Returns the value of attribute last_run
14 15 16 |
# File 'lib/roundhouse_ui/recurring.rb', line 14 def last_run @last_run end |
#name ⇒ Object
Returns the value of attribute name
14 15 16 |
# File 'lib/roundhouse_ui/recurring.rb', line 14 def name @name end |
#queue ⇒ Object
Returns the value of attribute queue
14 15 16 |
# File 'lib/roundhouse_ui/recurring.rb', line 14 def queue @queue end |
#schedule ⇒ Object
Returns the value of attribute schedule
14 15 16 |
# File 'lib/roundhouse_ui/recurring.rb', line 14 def schedule @schedule end |
#source ⇒ Object
Returns the value of attribute source
14 15 16 |
# File 'lib/roundhouse_ui/recurring.rb', line 14 def source @source end |
Instance Method Details
#enabled? ⇒ Boolean
16 |
# File 'lib/roundhouse_ui/recurring.rb', line 16 def enabled? = enabled != false |
#expected_interval ⇒ Object
The interesting question is not "what is the crontab" — it is "this says hourly and has not run in three days". That needs the schedule's expected interval, which needs a cron parser.
Fugit ships with both sidekiq-cron and sidekiq-scheduler, so it is present wherever this feature is. Where it is not, staleness is simply unknown rather than guessed.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/roundhouse_ui/recurring.rb', line 25 def expected_interval return nil unless defined?(::Fugit) parsed = ::Fugit.parse(schedule.to_s) return nil unless parsed.respond_to?(:next_time) a = parsed.next_time(Time.now) b = parsed.next_time(a.to_t + 1) (b.to_t - a.to_t).to_f rescue StandardError nil end |
#overdue? ⇒ Boolean
Overdue by more than one whole interval. One interval of slack on purpose: a job due at :00 and running at :00:07 is not late, and a view that says it is gets ignored.
41 42 43 44 45 46 |
# File 'lib/roundhouse_ui/recurring.rb', line 41 def overdue? interval = expected_interval return false if interval.nil? || last_run.nil? || !enabled? Time.now - last_run > interval * 2 end |
#status ⇒ Object
48 49 50 51 52 53 |
# File 'lib/roundhouse_ui/recurring.rb', line 48 def status return :paused unless enabled? return :unknown if last_run.nil? overdue? ? :overdue : :ok end |