Class: Pazuzu::Instance

Inherits:
Object
  • Object
show all
Includes:
Utility::Runnable
Defined in:
lib/pazuzu/instance.rb

Constant Summary collapse

SHUTDOWN_GRACE_TIME =

Time that we give processes to shut down normally on SIGTERM.

10.seconds

Instance Attribute Summary collapse

Attributes included from Utility::Runnable

#started_at, #stopped_at

Instance Method Summary collapse

Methods included from Utility::Runnable

#run_state, #start!, #stop!, #wait_for_state_change!

Constructor Details

#initialize(worker, index, root_path, command_line) ⇒ Instance

Returns a new instance of Instance.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pazuzu/instance.rb', line 10

def initialize(worker, index, root_path, command_line)
  @worker = worker
  @index = index
  @logger = Utility::AnnotatedLogger.new(
    @worker.application.supervisor.logger, qname)
  @root_path = root_path
  @command_line = command_line
  @tailer = Utility::OutputTailer.new(
    :limit => 5000,
    :on_line => proc { |timestamp, line| @logger.info("[output] #{line}") })
  @flap_limiter = Utility::RateLimiter.new(0.1)
  @recovery_count = 0
  @cgroup = @worker.application.supervisor.cgroup_for_instance(self)
  super()
end

Instance Attribute Details

#command_lineObject (readonly)

Returns the value of attribute command_line.



40
41
42
# File 'lib/pazuzu/instance.rb', line 40

def command_line
  @command_line
end

#indexObject (readonly)

Returns the value of attribute index.



42
43
44
# File 'lib/pazuzu/instance.rb', line 42

def index
  @index
end

#pidObject (readonly)

Returns the value of attribute pid.



44
45
46
# File 'lib/pazuzu/instance.rb', line 44

def pid
  @pid
end

#recovery_countObject (readonly)

Returns the value of attribute recovery_count.



45
46
47
# File 'lib/pazuzu/instance.rb', line 45

def recovery_count
  @recovery_count
end

#root_pathObject (readonly)

Returns the value of attribute root_path.



43
44
45
# File 'lib/pazuzu/instance.rb', line 43

def root_path
  @root_path
end

#workerObject (readonly)

Returns the value of attribute worker.



41
42
43
# File 'lib/pazuzu/instance.rb', line 41

def worker
  @worker
end

Instance Method Details

#attachable?Boolean

Does this instance have any unattached PIDs running?

Returns:

  • (Boolean)


27
28
29
# File 'lib/pazuzu/instance.rb', line 27

def attachable?
  run_state == :stopped && @cgroup.pids.any?
end

#log_entriesObject



35
36
37
38
# File 'lib/pazuzu/instance.rb', line 35

def log_entries
  source = qname
  return @tailer.entries.map { |(time, message)| [source, time, message] }
end

#qnameObject



31
32
33
# File 'lib/pazuzu/instance.rb', line 31

def qname
  [@worker.qname, @index].join('.')
end