Class: Moon::Scheduler::Jobs::Base

Inherits:
Object
  • Object
show all
Includes:
Activatable, Eventable
Defined in:
lib/moon/packages/scheduler/jobs/base.rb

Overview

Base class for all Scheduler jobs, this is completely optional for custom user jobs, as long as they implement the basic methods for the job API, (#update, #done?).

Direct Known Subclasses

Process, TimeBase

Instance Attribute Summary collapse

Instance Method Summary collapse

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, #typing

Constructor Details

#initialize(&block) ⇒ Base

Returns a new instance of Base.


31
32
33
34
35
36
37
38
# File 'lib/moon/packages/scheduler/jobs/base.rb', line 31

def initialize(&block)
  @callback = block
  @id = Random.random.base64(16)
  @active = true
  @killed = false
  @uptime = 0.0
  initialize_eventable
end

Instance Attribute Details

#activeBoolean

Returns active is the object active?.

Returns:

  • (Boolean)

    active is the object active?


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

def active
  @active
end

#idString (readonly)

Returns:


19
20
21
# File 'lib/moon/packages/scheduler/jobs/base.rb', line 19

def id
  @id
end

#keyObject

Returns:


29
30
31
# File 'lib/moon/packages/scheduler/jobs/base.rb', line 29

def key
  @key
end

#killedBoolean (readonly)

Returns:


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

def killed
  @killed
end

#uptimeFloat (readonly)

How long has this job been running?

Returns:


23
24
25
# File 'lib/moon/packages/scheduler/jobs/base.rb', line 23

def uptime
  @uptime
end

Instance Method Details

#done?Boolean

Is this job done?

Returns:


43
44
45
# File 'lib/moon/packages/scheduler/jobs/base.rb', line 43

def done?
  killed?
end

#killself

Sets the killed flag

Returns:

  • (self)

71
72
73
74
# File 'lib/moon/packages/scheduler/jobs/base.rb', line 71

def kill
  @killed = true
  self
end

#killed?Boolean

Was the job killed?

Returns:


79
80
81
# File 'lib/moon/packages/scheduler/jobs/base.rb', line 79

def killed?
  @killed
end

#trigger_callback(*args) ⇒ Object

Calls the callback


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

def trigger_callback(*args)
  @callback.call(*args) if @callback
end

#update(delta) ⇒ Object

Parameters:


62
63
64
65
66
# File 'lib/moon/packages/scheduler/jobs/base.rb', line 62

def update(delta)
  return unless active?
  update_job(delta)
  @uptime += delta
end

#update_job(delta) ⇒ Object

This method is abstract.

Called everytime the Job updates, use this method to continous updating jobs.

Parameters:


57
58
59
# File 'lib/moon/packages/scheduler/jobs/base.rb', line 57

def update_job(delta)
  #
end