Class: Sponges::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/sponges/runner.rb

Overview

This class concern is to create a Supervisor, set some signals handlers and watch over the supervisor.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, block) ⇒ Runner

Returns a new instance of Runner.



9
10
11
12
13
14
15
16
17
# File 'lib/sponges/runner.rb', line 9

def initialize(name, options = {}, block)
  @name, @block = name, block
  @options = default_options.merge options
  @store = Sponges::Store.new(@name)
  if store.running?
    Sponges.logger.error "Runner #{@name} already started."
    exit
  end
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



7
8
9
# File 'lib/sponges/runner.rb', line 7

def store
  @store
end

Instance Method Details

#startObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sponges/runner.rb', line 19

def start
  if daemonize?
    Sponges.logger.info "Supervisor daemonized."
    Process.daemon
  end
  Sponges.logger.info "Runner #{@name} start message received."
  @supervisor = fork_supervisor
  trap_signals
  Sponges.logger.info "Supervisor started with #{@supervisor} pid."
  Process.waitpid(@supervisor) unless daemonize?
end