lib/zhong/web.rb in zhong-0.1.5 vs lib/zhong/web.rb in zhong-0.1.6

- old
+ new

@@ -1,7 +1,6 @@ # frozen_string_literal: true -require "tilt/erubis" require "erb" require "sinatra/base" require "zhong" require "zhong/web_helpers" @@ -27,25 +26,25 @@ set :public_folder, proc { "#{root}/assets" } set :views, proc { "#{root}/views" } helpers WebHelpers - get '/' do + get "/" do index erb :index end - post '/' do - if params['disable'] - if job = Zhong.jobs[params['disable']] - job.disable - end - elsif params['enable'] - if job = Zhong.jobs[params['enable']] - job.enable - end + post "/" do + if params["disable"] + job = Zhong.jobs[params["disable"]] + + job.disable if job + elsif params["enable"] + job = Zhong.jobs[params["enable"]] + + job.enable if job end index erb :index @@ -53,33 +52,21 @@ def index @jobs = Zhong.jobs.values @last_runs = zhong_mget(@jobs, "last_ran") @disabled = zhong_mget(@jobs, "disabled") - @hosts = safe_mget(Zhong.redis.scan_each(match: "zhong:heartbeat:*").to_a).map do |k, v| - host, pid = k.split("zhong:heartbeat:", 2)[1].split("#", 2) - {host: host, pid: pid, last_seen: Time.at(v.to_i)} - end + @hosts = Zhong.all_heartbeats end def zhong_mget(jobs, key) keys = jobs.map(&:to_s) - ret = safe_mget(keys.map { |j| "zhong:#{key}:#{j}" }) + ret = Zhong::Util.safe_mget(keys.map { |j| "zhong:#{key}:#{j}" }) Hash[keys.map { |j| [j, ret["zhong:#{key}:#{j}"]] }] end - - def safe_mget(keys) - if keys.length > 0 - Zhong.redis.mapped_mget(*keys) - else - {} - end - end end end -if defined?(::ActionDispatch::Request::Session) && - !::ActionDispatch::Request::Session.respond_to?(:each) +if defined?(::ActionDispatch::Request::Session) && !::ActionDispatch::Request::Session.respond_to?(:each) # mperham/sidekiq#2460 # Rack apps can't reuse the Rails session store without # this monkeypatch class ActionDispatch::Request::Session def each(&block)