Class: App
- Inherits:
-
Object
- Object
- App
- Defined in:
- lib/grid_runner/applications.rb
Constant Summary collapse
- PROCFILE =
File.open(Dir.pwd + "/Procfile")
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #display(color_index = rand(0..COLORS.length)) ⇒ Object
-
#initialize(name, command, status, pid) ⇒ App
constructor
A new instance of App.
- #kill! ⇒ Object
- #log ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(name, command, status, pid) ⇒ App
Returns a new instance of App.
8 9 10 11 12 13 |
# File 'lib/grid_runner/applications.rb', line 8 def initialize(name, command, status, pid) @name = name @command = command @status = status @pid = pid end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/grid_runner/applications.rb', line 6 def command @command end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/grid_runner/applications.rb', line 6 def name @name end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
6 7 8 |
# File 'lib/grid_runner/applications.rb', line 6 def pid @pid end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/grid_runner/applications.rb', line 6 def status @status end |
Class Method Details
.all ⇒ Object
15 16 17 18 19 |
# File 'lib/grid_runner/applications.rb', line 15 def self.all PROCFILE.map do |line| App.from_procfile(line) end end |
Instance Method Details
#display(color_index = rand(0..COLORS.length)) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/grid_runner/applications.rb', line 35 def display(color_index = rand(0..COLORS.length)) puts Rainbow("#{name} ").send(COLORS[color_index % COLORS.length]).underline puts "status: #{status}" puts "pid: #{pid}" if status == :running puts "log: #{log.path}" puts end |
#kill! ⇒ Object
43 44 45 46 47 48 |
# File 'lib/grid_runner/applications.rb', line 43 def kill! if status == :running Process.kill("HUP", pid.to_i) puts Rainbow("killing #{name}").red end end |
#log ⇒ Object
50 51 52 |
# File 'lib/grid_runner/applications.rb', line 50 def log File.open((Dir.pwd + "/logs/" + "#{name}.log"), "w+") end |
#run ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/grid_runner/applications.rb', line 54 def run puts Rainbow("running #{name}").green Process.spawn( ENV, command, out: [log.path, "w"], err: [log.path, "w"], :in => "/dev/null" ) end |