Class: RoundhouseUi::Recurring::Task

Inherits:
Struct
  • Object
show all
Defined in:
lib/roundhouse_ui/recurring.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled

Returns:

  • (Object)

    the current value of enabled



14
15
16
# File 'lib/roundhouse_ui/recurring.rb', line 14

def enabled
  @enabled
end

#klassObject

Returns the value of attribute klass

Returns:

  • (Object)

    the current value of klass



14
15
16
# File 'lib/roundhouse_ui/recurring.rb', line 14

def klass
  @klass
end

#last_runObject

Returns the value of attribute last_run

Returns:

  • (Object)

    the current value of last_run



14
15
16
# File 'lib/roundhouse_ui/recurring.rb', line 14

def last_run
  @last_run
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



14
15
16
# File 'lib/roundhouse_ui/recurring.rb', line 14

def name
  @name
end

#queueObject

Returns the value of attribute queue

Returns:

  • (Object)

    the current value of queue



14
15
16
# File 'lib/roundhouse_ui/recurring.rb', line 14

def queue
  @queue
end

#scheduleObject

Returns the value of attribute schedule

Returns:

  • (Object)

    the current value of schedule



14
15
16
# File 'lib/roundhouse_ui/recurring.rb', line 14

def schedule
  @schedule
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



14
15
16
# File 'lib/roundhouse_ui/recurring.rb', line 14

def source
  @source
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


16
# File 'lib/roundhouse_ui/recurring.rb', line 16

def enabled? = enabled != false

#expected_intervalObject

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.

Returns:

  • (Boolean)


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

#statusObject



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