64 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
		
		
			
		
	
	
			64 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
|   | module Devops | ||
|  |   module Version2_0 | ||
|  |     module Handler | ||
|  |       class Report | ||
|  | 
 | ||
|  |         def self.reports_all | ||
|  |           lambda { | ||
|  |             options = {} | ||
|  |             ["project", "deploy_env", "type", "created_by", "date_from", "date_to", "sort", "status", "max_number", "chef_node_name"].each do |k| | ||
|  |               options[k] = params[k] unless params[k].nil? | ||
|  |             end | ||
|  |             attributes_keys = params.keys.select{|k| k =~ /attributes\.*/} | ||
|  |             attributes_keys.each do |ak| | ||
|  |               options[ak] = params[ak] | ||
|  |             end | ||
|  |             json Devops::Db.connector.reports(options).map{|r| r.to_hash} | ||
|  |           } | ||
|  |         end | ||
|  | 
 | ||
|  |         def self.reports_latest | ||
|  |           lambda { | ||
|  |             options = {} | ||
|  |             ["project", "deploy_env", "type", "created_by", "date_from", "date_to", "sort", "status", "chef_node_name"].each do |k| | ||
|  |               options[k] = params[k] unless params[k].nil? | ||
|  |             end | ||
|  |             attributes_keys = params.keys.select{|k| k =~ /attributes\.*/} | ||
|  |             attributes_keys.each do |ak| | ||
|  |               options[ak] = params[ak] | ||
|  |             end | ||
|  |             json Devops::Db.connector.latest_reports(options).map{|r| r.to_hash} | ||
|  |           } | ||
|  |         end | ||
|  | 
 | ||
|  |         def self.attributes_all | ||
|  |           lambda{ | ||
|  |             json Devops::Db.connector.reports_attributes_values(params["name"]) | ||
|  |           } | ||
|  |         end | ||
|  | 
 | ||
|  |         def self.report | ||
|  |           lambda{ | ||
|  |             begin | ||
|  |               r = Devops::Db.connector.report(params[:id]) | ||
|  |               file = r.file | ||
|  |               return [404, "Report '#{params[:id]}' does not exist"] unless File.exists? file | ||
|  |               @text = Rack::Utils.escape_html(File.read(file)) | ||
|  |               @done = completed?(params[:id]) | ||
|  |             rescue RecordNotFound => e | ||
|  |               if task_status(params[:id]) == Worker::STATUS::IN_QUEUE | ||
|  |                 @text = "Task '#{params[:id]}' has been queued" | ||
|  |                 @done = false | ||
|  |               else | ||
|  |                 raise e | ||
|  |               end | ||
|  |             end | ||
|  |             erb :index | ||
|  |           } | ||
|  |         end | ||
|  |       end | ||
|  |     end | ||
|  |   end | ||
|  | end | ||
|  | 
 |