Class: Moon::Scheduler::Jobs::TimeBase

Inherits:
Base show all
Defined in:
lib/moon/packages/scheduler/jobs/time_base.rb

Overview

TimeBase is the base class for all timebound events.

Direct Known Subclasses

Interval, TimedProcess, Timeout

Instance Attribute Summary collapse

Attributes inherited from Base

#active, #id, #key, #killed, #uptime

Instance Method Summary collapse

Methods inherited from Base

#kill, #killed?, #trigger_callback, #update

Methods included from Activatable

#activate, #active?, #deactivate

Methods included from Eventable

#allow_event?, #clear_events, #each_listener, #each_typed_listener, filter_from_options, #has_events?, #initialize_eventable, #off, #on, #ppd_ev, #trigger, #typing

Constructor Details

#initialize(duration, &block) ⇒ TimeBase

Returns a new instance of TimeBase.

Parameters:


15
16
17
18
# File 'lib/moon/packages/scheduler/jobs/time_base.rb', line 15

def initialize(duration, &block)
  @time = self.duration = TimeUtil.to_duration(duration)
  super(&block)
end

Instance Attribute Details

#durationFloat

Returns:


12
13
14
# File 'lib/moon/packages/scheduler/jobs/time_base.rb', line 12

def duration
  @duration
end

#timeFloat (readonly)

Returns:


9
10
11
# File 'lib/moon/packages/scheduler/jobs/time_base.rb', line 9

def time
  @time
end

Instance Method Details

#done?Boolean

Returns:


31
32
33
# File 'lib/moon/packages/scheduler/jobs/time_base.rb', line 31

def done?
  killed? || timeout?
end

#finishObject

Finish will force the job to stop, and call #on_timeout, use #stop instead if you only wish to end the job only, without calling #on_timeout


73
74
75
76
# File 'lib/moon/packages/scheduler/jobs/time_base.rb', line 73

def finish
  stop
  on_timeout
end

#rateFloat

Returns:


36
37
38
# File 'lib/moon/packages/scheduler/jobs/time_base.rb', line 36

def rate
  @time / @duration
end

#restartObject

Sets the time to the duration, ultimately restarting the job's internal timer.


66
67
68
# File 'lib/moon/packages/scheduler/jobs/time_base.rb', line 66

def restart
  @time += @duration
end

#stopObject

Sets the time to 0.0, which is the end.


60
61
62
# File 'lib/moon/packages/scheduler/jobs/time_base.rb', line 60

def stop
  @time = 0.0
end

#timeout?Boolean

Returns:


26
27
28
# File 'lib/moon/packages/scheduler/jobs/time_base.rb', line 26

def timeout?
  @time <= 0
end

#update_job(delta) ⇒ Object

Parameters:


53
54
55
56
57
# File 'lib/moon/packages/scheduler/jobs/time_base.rb', line 53

def update_job(delta)
  @time -= delta
  update_job_step(delta)
  on_timeout if @time <= 0
end

#update_job_step(delta) ⇒ Object

Parameters:


49
50
# File 'lib/moon/packages/scheduler/jobs/time_base.rb', line 49

def update_job_step(delta)
end