106 lines
2.2 KiB
Ruby
106 lines
2.2 KiB
Ruby
require 'sinatra/base'
|
|
|
|
class Report< Sinatra::Base
|
|
|
|
def initialize config, version
|
|
super()
|
|
@@config = config
|
|
@paths = {
|
|
"server" => @@config[:server_report_dir_v2],
|
|
"deploy" => @@config[:deploy_report_dir_v2],
|
|
"project" => @@config[:project_report_dir_v2]
|
|
}
|
|
end
|
|
|
|
enable :inline_templates
|
|
|
|
get "/all" do
|
|
res = {}
|
|
uri = URI.parse(request.url)
|
|
pref = File.dirname(uri.path)
|
|
@paths.each do |key, dir|
|
|
files = []
|
|
Dir[File.join(dir, "/**/*")].each do |f|
|
|
next if File.directory?(f)
|
|
jid = File.basename(f)
|
|
uri.path = File.join(pref, key, f[dir.length..-1])
|
|
o = {
|
|
"file" => uri.to_s,
|
|
"created" => File.ctime(f).to_s,
|
|
"status" => task_status(jid)
|
|
}
|
|
files.push o
|
|
end
|
|
res[key] = files
|
|
end
|
|
json res
|
|
end
|
|
|
|
get "/server/:id" do
|
|
dir = @paths["server"] || ""
|
|
file = File.join(dir, params[:id])
|
|
return [404, "Report '#{params[:id]}' does not exist"] unless File.exists? file
|
|
@text = File.read(file)
|
|
@done = completed?(params[:id])
|
|
erb :index
|
|
end
|
|
|
|
get "/deploy/:id" do
|
|
dir = @paths["deploy"] || ""
|
|
file = File.join(dir, params[:id])
|
|
return [404, "Report '#{params[:id]}' does not exist"] unless File.exists? file
|
|
@text = File.read(file)
|
|
@done = completed?(params[:id])
|
|
erb :index
|
|
end
|
|
|
|
get "/project/:project/:env/:id" do
|
|
dir = @paths["project"] || ""
|
|
file = File.join(dir, params[:project], params[:env], params[:id])
|
|
return [404, "Report '#{params[:id]}' for project '#{params[:project]}' and env '#{params[:env]}' does not exist"] unless File.exists? file
|
|
@text = File.read(file)
|
|
@done = completed?(params[:id])
|
|
erb :index
|
|
end
|
|
|
|
get "/favicon.ico" do
|
|
[404, ""]
|
|
end
|
|
|
|
def completed? id
|
|
r = task_status(id)
|
|
r == "completed" or r == "failed"
|
|
end
|
|
|
|
def task_status id
|
|
r = Sidekiq.redis do |connection|
|
|
connection.hget("devops", id)
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
__END__
|
|
|
|
@@ layout
|
|
<html>
|
|
<head>
|
|
<% unless @done %>
|
|
<script>
|
|
function reload() {
|
|
location.reload();
|
|
}
|
|
setTimeout(reload, 5000);
|
|
</script>
|
|
<% end %>
|
|
</head>
|
|
<body>
|
|
<%= yield %>
|
|
</body>
|
|
</html>
|
|
|
|
@@ index
|
|
<pre>
|
|
<%= @text %>
|
|
</pre>
|