Class: CruiseFace::Console

Inherits:
Object
  • Object
show all
Defined in:
lib/cruise_face/console.rb

Defined Under Namespace

Classes: UIBuilder

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipeline_names) ⇒ Console

Returns a new instance of Console.



114
115
116
117
118
# File 'lib/cruise_face/console.rb', line 114

def initialize(pipeline_names)
  @pipeline_names = pipeline_names
  @mutex = Mutex.new
  @status = {}
end

Class Method Details

.show_detailsObject



110
111
112
# File 'lib/cruise_face/console.rb', line 110

def self.show_details
  ENV['SHOW_CRUISE_DETAILS'] == 'true'
end

.show_details=(enable) ⇒ Object



106
107
108
# File 'lib/cruise_face/console.rb', line 106

def self.show_details=(enable)
  ENV['SHOW_CRUISE_DETAILS'] = enable.to_s
end

Instance Method Details

#refreshObject



151
152
153
154
155
156
157
158
159
160
161
# File 'lib/cruise_face/console.rb', line 151

def refresh
  status_dump = @mutex.synchronize { @status.dup }.collect do |pipeline, status|
    UIBuilder.instance.to_string(status)
  end.join("\n")
  print %x{clear}
  dashboard = "---- #{Time.now.strftime("%b %d %H:%M:%S")} ----\n"
  dashboard << CGI.unescapeHTML(status_dump) << "\n"
  dashboard << "Type 'open' to open Cruise dashboard" << "\n"
  dashboard << "Type 'show/hide' to show/hide details" << "\n"
  puts dashboard
end

#startObject



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/cruise_face/console.rb', line 120

def start
  @pipeline_names.each do |name|
    start_fetch(name)
  end

  puts "Initializing first report"
  loop do
    print '.'
    STDOUT.flush
    sleep 1
    break unless @mutex.synchronize { @status.empty? }
  end
  puts "\nGot first report"
  start_commander

  loop do
    refresh
    sleep 5
  end
end

#start_commanderObject



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/cruise_face/console.rb', line 163

def start_commander
  Thread.start do
    loop do
      command = gets.strip
      case command
      when /^(open|start)$/
        if Resource.site.nil?
          puts "ERROR: cruise server url not found"
        else
          system "#{command} #{Resource.site.to_s.inspect}"
        end
      when /^hide$/
        Console.show_details = false;
        refresh
      when /^show$/
        Console.show_details = true;
        refresh
      else
        puts "Unknown command"
      end
    end
  end
end

#start_fetch(pipeline) ⇒ Object



141
142
143
144
145
146
147
148
149
# File 'lib/cruise_face/console.rb', line 141

def start_fetch(pipeline)
  Thread.start do
    loop do
      pipeline_status = %x[#{$0} -o -p #{pipeline.inspect}]
      @mutex.synchronize { @status[pipeline] = pipeline_status }
      sleep 10
    end
  end
end