Class: SupervisorInfo

Inherits:
Object
  • Object
show all
Includes:
HotPotato::Core
Defined in:
lib/hot_potato/supervisor_info.rb

Constant Summary

Constants included from HotPotato::Core

HotPotato::Core::CONFIG_PATH

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HotPotato::Core

#acquire_lock, #config, #log, #queue_inject, #queue_subscribe, #release_lock, #set_logger, #stat

Constructor Details

#initialize(options = {}) ⇒ SupervisorInfo

Returns a new instance of SupervisorInfo.



7
8
9
10
11
12
13
# File 'lib/hot_potato/supervisor_info.rb', line 7

def initialize(options = {})
  @data = {}
  @data[:started_at] = options[:started_at] || Time.now
  @data[:updated_at] = options[:updated_at] || @data[:started_at]
  @data[:hostname]   = options[:hostname]   || Socket.gethostname
  @data[:pid]        = options[:pid]        || Process.pid
end

Class Method Details

.json_create(o) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/hot_potato/supervisor_info.rb', line 55

def self.json_create(o)
  options = {}
  options[:started_at] = o["started_at"]
  options[:updated_at] = o["updated_at"]
  options[:pid]        = o["pid"]   
  options[:hostname]   = o["hostname"]    
  new options
end

Instance Method Details

#app_tasksObject



23
24
25
# File 'lib/hot_potato/supervisor_info.rb', line 23

def app_tasks
  stat.keys("hotpotato.apptask.#{@data[:hostname]}.*").count
end

#hostnameObject



27
28
29
# File 'lib/hot_potato/supervisor_info.rb', line 27

def hostname
  @data[:hostname]
end

#keyObject



15
16
17
# File 'lib/hot_potato/supervisor_info.rb', line 15

def key 
  "hotpotato.supervisor.#{@data[:hostname]}.#{@data[:pid]}"
end

#pidObject



31
32
33
# File 'lib/hot_potato/supervisor_info.rb', line 31

def pid
  @data[:pid]
end

#started_atObject



35
36
37
38
# File 'lib/hot_potato/supervisor_info.rb', line 35

def started_at
  return nil unless @data[:started_at]
  DateTime.parse(@data[:started_at])
end

#to_json(*a) ⇒ Object



49
50
51
52
53
# File 'lib/hot_potato/supervisor_info.rb', line 49

def to_json(*a)
  result = @data
  result["json_class"] = self.class.name
  result.to_json(*a)
end

#to_sObject



19
20
21
# File 'lib/hot_potato/supervisor_info.rb', line 19

def to_s
  @data.to_s
end

#touchObject



45
46
47
# File 'lib/hot_potato/supervisor_info.rb', line 45

def touch
  @data[:updated_at] = Time.now
end

#updated_atObject



40
41
42
43
# File 'lib/hot_potato/supervisor_info.rb', line 40

def updated_at
  return nil unless @data[:updated_at]
  DateTime.parse(@data[:updated_at])
end