lib/pmux-logview/controller.rb in pmux-logview-0.3.4 vs lib/pmux-logview/controller.rb in pmux-logview-0.3.10

- old
+ new

@@ -1,5 +1,7 @@ +# -*- coding: utf-8 -*- + require 'sinatra' require 'sinatra/base' require 'json' require 'erb' require 'fileutils' @@ -17,10 +19,11 @@ @@log_level = "info" @@syslog_facility = "daemon" @@use_syslog = false @@use_basic_auth = true @@default_user = "pmux" + @@cache_expire_time = 86400 @@model = nil @@logger = nil @user = nil set :public_folder, File.dirname(__FILE__) + '/static' set :views, File.dirname(__FILE__) + "/views" @@ -46,27 +49,29 @@ @@use_syslog = args[key] when "syslog_facility" @@syslog_facility = args[key] when "default_user" @@default_user = args[key] + when "cache_expire_time" + @@cache_expire_time = args[key] end } log_file_path = File.expand_path([@@log_dir_path, @@log_filename].join(File::SEPARATOR)) @@logger.foreground(@@foreground) @@logger.open(log_file_path, @@log_level, @@use_syslog, @@syslog_facility) AuthHelper.update(@@password_file_path) - @@model = Model.new(@@cache_dir_path) + @@model = Model.new(@@cache_dir_path, @@cache_expire_time) end configure do log_file_path = File.expand_path([@@log_dir_path, @@log_filename].join(File::SEPARATOR)) @@logger = LoggerWrapper.instance() @@logger.init() @@logger.open(log_file_path, @@log_level, @@use_syslog, @@syslog_facility) use Rack::CommonLogger, @@logger AuthHelper.init(@@password_file_path) - @@model = Model.new(@@cache_dir_path) + @@model = Model.new(@@cache_dir_path, @@cache_expire_time) end def logger return env['user.logger'] || env['rack.logger'] end @@ -90,15 +95,14 @@ @user = @@default_user if @user.nil? @user = AuthHelper.check_auth!(request, response, @auth, @@password_file_path) if @@use_basic_auth @@logger.info("access user #{@user}") data = {} validations = { - "sort_key" => { "default" => "start_time", "type" => String, "values" => [ "job_id", "mapper", "start_time", "end_time", "elapsed_time"] }, "sort_order" => { "default" => "desc", "type" => String, "values" => [ "asc", "desc" ] }, - "type" => { "default" => "archive", "type" => String, "values" => [ "archive", "update" ] }, "nitems" => { "default" => 20, "type" => Integer, "values" => nil }, "page" => { "default" => 0, "type" => Integer, "values" => nil }, - "jobs_cookie" => { "default" => 0, "type" => Integer, "values" => nil }, + "start_time_msec" => { "default" => nil, "type" => Integer, "values" => nil }, + "end_time_msec" => { "default" => nil, "type" => Integer, "values" => nil }, } validations.each_key{|key| if params.key?(key) if (validations[key]["type"] == Integer) data[key] = params[key].to_i