Class: Slnky::Service::Base
- Inherits:
-
Object
- Object
- Slnky::Service::Base
- Defined in:
- lib/slnky/service.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#subscriber ⇒ Object
readonly
Returns the value of attribute subscriber.
-
#timers ⇒ Object
readonly
Returns the value of attribute timers.
Class Method Summary collapse
Instance Method Summary collapse
- #handle_command(event, data) ⇒ Object
- #handle_heartbeat ⇒ Object
- #handle_restart(name, data) ⇒ Object
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #start ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
14 15 16 17 |
# File 'lib/slnky/service.rb', line 14 def initialize config.service = name @server_down = false end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/slnky/service.rb', line 12 def name @name end |
#subscriber ⇒ Object (readonly)
Returns the value of attribute subscriber.
10 11 12 |
# File 'lib/slnky/service.rb', line 10 def subscriber @subscriber end |
#timers ⇒ Object (readonly)
Returns the value of attribute timers.
11 12 13 |
# File 'lib/slnky/service.rb', line 11 def timers @timers end |
Class Method Details
.periodic(seconds, method) ⇒ Object Also known as: timer
104 105 106 |
# File 'lib/slnky/service.rb', line 104 def periodic(seconds, method) Slnky::Service.timers.add(seconds, method) end |
.subscribe(name, method) ⇒ Object
100 101 102 |
# File 'lib/slnky/service.rb', line 100 def subscribe(name, method) Slnky::Service.subscriber.add(name, method) end |
Instance Method Details
#handle_command(event, data) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/slnky/service.rb', line 35 def handle_command(event, data) if command command.handle(event, data) else log.error "no comamnd support for #{name}" end end |
#handle_heartbeat ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/slnky/service.rb', line 49 def handle_heartbeat return if @server_down Slnky.heartbeat(name) rescue => e log.info "could not post heartbeat, server down? #{e.}" @server_down = true end |
#handle_restart(name, data) ⇒ Object
43 44 45 46 47 |
# File 'lib/slnky/service.rb', line 43 def handle_restart(name, data) # if we get this event, just stop. upstart will start us again. log.warn "received restart event" transport.stop!('Restarted') end |
#start ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/slnky/service.rb', line 19 def start transport.start!(self) do |_| log.info "#{config.service} running #{config.environment}" run subscriber.add "slnky.#{name}.command", :handle_command subscriber.add "slnky.help.command", :handle_command subscriber.add "slnky.service.restart", :handle_restart timers.add 5.seconds, :handle_heartbeat unless config.development? subscriber.each do |name, method| log.info "subscribed to: #{name} -> #{self.class.name}.#{method}" end end end |