Class: Omega::Server::PeriodicEvent

Inherits:
HandledEvent show all
Defined in:
lib/omega/server/event.rb

Overview

Periodic event, which automatically schedules another to be run at a specified interval on execution

Constant Summary collapse

DEFAULT_INTERVAL =

Default interval which will be set if not specified

60

Instance Attribute Summary collapse

Attributes inherited from Event

#handlers, #id, #registry, #timestamp, #type

Instance Method Summary collapse

Methods inherited from HandledEvent

#handlers_json

Methods inherited from Event

#event_args, #handlers_json, #invoke, json_create, #json_data, #should_exec?, #time_elapsed?, #to_s

Constructor Details

#initialize(args = {}) ⇒ PeriodicEvent

Periodic Event initializer


167
168
169
170
171
# File 'lib/omega/server/event.rb', line 167

def initialize(args = {})
  attr_from_args args, :interval => DEFAULT_INTERVAL,
                       :template_event => nil
  super(args)
end

Instance Attribute Details

#intervalObject

Interval in seconds between spawing events


130
131
132
# File 'lib/omega/server/event.rb', line 130

def interval
  @interval
end

#template_eventObject

Event which to run at the specified interval


133
134
135
# File 'lib/omega/server/event.rb', line 133

def template_event
  @template_event
end

Instance Method Details

#periodic_json_dataObject

Return periodic event json data


174
175
176
177
# File 'lib/omega/server/event.rb', line 174

def periodic_json_data
  {:interval       => interval,
   :template_event => template_event}
end

#to_json(*a) ⇒ Object

Convert event to json representation and return it


180
181
182
183
184
185
# File 'lib/omega/server/event.rb', line 180

def to_json(*a)
  {
    'json_class' => self.class.name,
    'data'       => json_data.merge(periodic_json_data)
  }.to_json(*a)
end