Class: Procodile::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/procodile/process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, name, command, options = {}) ⇒ Process

Returns a new instance of Process.



12
13
14
15
16
17
18
# File 'lib/procodile/process.rb', line 12

def initialize(config, name, command, options = {})
  @config = config
  @name = name
  @command = command
  @options = options
  @log_color = 0
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



8
9
10
# File 'lib/procodile/process.rb', line 8

def command
  @command
end

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/procodile/process.rb', line 6

def config
  @config
end

#log_colorObject

Returns the value of attribute log_color.



10
11
12
# File 'lib/procodile/process.rb', line 10

def log_color
  @log_color
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/procodile/process.rb', line 7

def name
  @name
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/procodile/process.rb', line 9

def options
  @options
end

Instance Method Details

#generate_instances(quantity = self.quantity, start_number = 1) ⇒ Object

Generate an array of new instances for this process (based on its quantity)



71
72
73
# File 'lib/procodile/process.rb', line 71

def generate_instances(quantity = self.quantity, start_number = 1)
  quantity.times.map { |i| Instance.new(self, i + start_number) }
end

#log_pathObject

Return the path where log output for this process should be written to. If none, output will be written to the supervisor log.



45
46
47
# File 'lib/procodile/process.rb', line 45

def log_path
  @options['log_path'] ? File.expand_path(@options['log_path'], @config.root) : nil
end

#max_respawnsObject

The maximum number of times this process can be respawned in the given period



30
31
32
# File 'lib/procodile/process.rb', line 30

def max_respawns
  @options['max_respawns'] ? @options['max_respawns'].to_i : 5
end

#quantityObject

How many instances of this process should be started



23
24
25
# File 'lib/procodile/process.rb', line 23

def quantity
  @options['quantity'] || 1
end

#respawn_windowObject

The respawn window. One hour by default.



37
38
39
# File 'lib/procodile/process.rb', line 37

def respawn_window
  @options['respawn_window'] ? @options['respawn_window'].to_i : 3600
end

#restart_modeObject

Defines how this process should be restarted

start-term = start new instances and send term to children  usr1 = just send a usr1 signal to the current instance usr2 = just send a usr2 signal to the current instance term-start = stop the old instances, when no longer running, start a new one



64
65
66
# File 'lib/procodile/process.rb', line 64

def restart_mode
  @options['restart_mode'] || 'term-start'
end

#term_signalObject

 Return the signal to send to terminate the process



52
53
54
# File 'lib/procodile/process.rb', line 52

def term_signal
  @options['term_signal'] || 'TERM'
end

#to_hashObject

Return a hash



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/procodile/process.rb', line 78

def to_hash
  {
    :name => self.name,
    :log_color => self.log_color,
    :quantity => self.quantity,
    :max_respawns => self.max_respawns,
    :respawn_window => self.respawn_window,
    :command => self.command,
    :restart_mode => self.restart_mode,
    :log_path => self.log_path
  }
end