Class: Async::Background::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/async/background/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, job_class:, interval:, cron:, timeout:, next_run_at:) ⇒ Entry

Returns a new instance of Entry.



9
10
11
12
13
14
15
16
17
# File 'lib/async/background/entry.rb', line 9

def initialize(name:, job_class:, interval:, cron:, timeout:, next_run_at:)
  @name        = name
  @job_class   = job_class
  @interval    = interval
  @cron        = cron
  @timeout     = timeout
  @next_run_at = next_run_at
  @running     = false
end

Instance Attribute Details

#cronObject (readonly)

Returns the value of attribute cron.



6
7
8
# File 'lib/async/background/entry.rb', line 6

def cron
  @cron
end

#intervalObject (readonly)

Returns the value of attribute interval.



6
7
8
# File 'lib/async/background/entry.rb', line 6

def interval
  @interval
end

#job_classObject (readonly)

Returns the value of attribute job_class.



6
7
8
# File 'lib/async/background/entry.rb', line 6

def job_class
  @job_class
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/async/background/entry.rb', line 6

def name
  @name
end

#next_run_atObject

Returns the value of attribute next_run_at.



7
8
9
# File 'lib/async/background/entry.rb', line 7

def next_run_at
  @next_run_at
end

#runningObject

Returns the value of attribute running.



7
8
9
# File 'lib/async/background/entry.rb', line 7

def running
  @running
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



6
7
8
# File 'lib/async/background/entry.rb', line 6

def timeout
  @timeout
end

Instance Method Details

#reschedule(monotonic_now) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/async/background/entry.rb', line 19

def reschedule(monotonic_now)
  if interval
    @next_run_at += interval
    @next_run_at = monotonic_now + interval if @next_run_at <= monotonic_now
  else
    now_wall = Time.now
    wait = cron.next_time(now_wall).to_f - now_wall.to_f
    @next_run_at = monotonic_now + [wait, Async::Background::MIN_SLEEP_TIME].max
  end
end