lib/atomic_sidekiq/web.rb in atomic-sidekiq-1.1.2 vs lib/atomic_sidekiq/web.rb in atomic-sidekiq-1.1.3

- old
+ new

@@ -1,35 +1,40 @@ module AtomicSidekiq module Web VIEW_PATH = File.expand_path("../../web/views", __dir__) def self.registered(app) + register_inflight(app) + register_recovered(app) + end + + def self.register_inflight(app) app.get "/in-flight" do - Web.render_in_flight - end + @jobs = AtomicSidekiq::InFlightQueue.new.list + @total_size = @jobs.count + @count = (params[:count] || 25).to_i + @current_page = (params[:page] || 1).to_i - app.get "/recovered" do - Web.render_recovered + start_idx = (@current_page - 1) * @count + end_idx = (@current_page * @count) - 1 + @jobs = @jobs[start_idx..end_idx] + + erb File.read(File.join(VIEW_PATH, "in_flight.erb")) end end - def self.render_in_flight - @jobs = AtomicSidekiq::InFlightQueue.new.list - @total_size = @jobs.count - @count = 25 - @current_page = (params[:page] || 1).to_i - @jobs = @jobs[@current_page..(@current_page + @count)] - erb File.read(File.join(VIEW_PATH, "in_flight.erb")) - end + def self.register_recovered(app) + app.get "/recovered" do + @queues = AtomicSidekiq::RecoveredStats.new.stats_by_queue + @jobs = AtomicSidekiq::RecoveredStats.new.stats_by_job - def self.render_recovered - @queues = AtomicSidekiq::RecoveredStats.new.stats_by_queue - @jobs = AtomicSidekiq::RecoveredStats.new.stats_by_job - erb File.read(File.join(VIEW_PATH, "recovered.erb")) + erb File.read(File.join(VIEW_PATH, "recovered.erb")) + end end end end -require "sidekiq/web" unless defined?(Sidekiq::Web) -Sidekiq::Web.register(AtomicSidekiq::Web) -Sidekiq::Web.tabs["In-flight"] = "in-flight" -Sidekiq::Web.tabs["Recovered"] = "recovered" +if defined?(Sidekiq::Web) + Sidekiq::Web.register(AtomicSidekiq::Web) + Sidekiq::Web.tabs["In-flight"] = "in-flight" + Sidekiq::Web.tabs["Recovered"] = "recovered" +end