Skip to content

Commit

Permalink
Merge pull request #2 from AndyObtiva/main
Browse files Browse the repository at this point in the history
 Dynamic updates of global stats + refactorings/glimmer-upgrade
  • Loading branch information
mperham authored Nov 25, 2023
2 parents 98ebfa8 + 8ea4033 commit 953f72e
Show file tree
Hide file tree
Showing 16 changed files with 343 additions and 304 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/pkg/
/spec/reports/
/tmp/
.gladiator
.gladiator-scratchpad
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kuiq
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.1
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "glimmer-dsl-libui", "= 0.11.3"
gem "glimmer-dsl-libui", "= 0.11.4"
gem "sidekiq"

group :test do
Expand Down
6 changes: 2 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GEM
glimmer (2.7.3)
array_include_methods (~> 1.4.0)
facets (>= 3.1.0, < 4.0.0)
glimmer-dsl-libui (0.11.3)
glimmer-dsl-libui (0.11.4)
chunky_png (~> 1.4.0)
color (~> 1.8)
equalizer (= 0.0.11)
Expand All @@ -30,7 +30,6 @@ GEM
text-table (>= 1.2.4, < 2.0.0)
json (2.6.3)
language_server-protocol (3.17.0.3)
libui (0.1.2.pre)
libui (0.1.2.pre-arm64-darwin)
lint_roller (1.1.0)
matrix (0.4.2)
Expand Down Expand Up @@ -112,10 +111,9 @@ GEM

PLATFORMS
arm64-darwin-22
x86_64-linux

DEPENDENCIES
glimmer-dsl-libui (= 0.11.3)
glimmer-dsl-libui (= 0.11.4)
minitest
rake
sidekiq
Expand Down
4 changes: 3 additions & 1 deletion bin/kuiq
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env ruby

$LOAD_PATH.unshift File.expand_path(File.join(__dir__, '..', 'lib'))

require "kuiq/admin_ui"
AdminUI.launch
AdminUI.launch
8 changes: 4 additions & 4 deletions lib/kuiq/admin_ui.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require "glimmer-dsl-libui"
require "sidekiq"
require "sidekiq/api"
require "glimmer-dsl-libui"

require "kuiq/models"
require "kuiq/components"
require "kuiq/model/job_manager"
require "kuiq/view/dashboard"

class AdminUI
include Glimmer::LibUI::Application

before_body do
@job_manager = JobManager.new
@job_manager = Model::JobManager.new
end

after_body do
Expand Down
220 changes: 0 additions & 220 deletions lib/kuiq/components.rb

This file was deleted.

7 changes: 7 additions & 0 deletions lib/kuiq/model/job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Model
class Job
STATUSES = %i[processed failed busy enqueued retries scheduled dead]

attr_accessor :id, :status, :time
end
end
92 changes: 92 additions & 0 deletions lib/kuiq/model/job_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
require "kuiq/model/job"

module Model
class JobManager
REDIS_PROPERTIES = %w[redis_version uptime_in_days connected_clients used_memory_human used_memory_peak_human]

attr_accessor :jobs, :polling_interval
attr_reader :redis_url, :current_time, :docs_url, :locale, :locale_url, :redis_info

def initialize
@current_time = Time.now
@jobs = []
@polling_interval = 5
@redis_url = Sidekiq.redis { |c| c.config.server_url }
@current_time = Time.now.utc
@docs_url = "https://github.com/sidekiq/sidekiq/wiki"
@locale_url = "https://github.com/sidekiq/sidekiq/"
@locale = "en"
@redis_info = Sidekiq.default_configuration.redis_info
end

def stats
# do not cache in a variable to ensure getting the latest values when calling methods
# off of the Status object (e.g. when calling stats.processed)
Sidekiq::Stats.new
end

def processed = stats.processed

def failed = stats.failed

def busy = Sidekiq::WorkSet.new.size

def enqueued = stats.enqueued

def retries = stats.retry_size

def scheduled = stats.scheduled_size

def dead = stats.dead_size

def refresh
refresh_stats
refresh_redis_properties
end

def refresh_stats
Job::STATUSES.each do |status|
# notify_observers is added automatically by Glimmer when data-binding
# it enables manually triggering data-binding changes when needed
notify_observers(status)
end
end

def refresh_redis_properties
REDIS_PROPERTIES.each do |property|
# notify_observers is added automatically by Glimmer when data-binding
# it enables manually triggering data-binding changes when needed
redis_info.notify_observers(property)
end
end

def report_points
points = []
current_jobs = jobs.dup
start_time = @current_time
end_time = Time.now
time_length = (end_time - start_time).to_i
time_length.times do |n|
job_found = current_jobs.detect do |job|
job_delay = job.time - start_time
job_delay.between?(n, n + 1)
end
x = n * 15
y = job_found ? 5 : 195
points << [x, y]
end
translate_points(points)
points
end

def translate_points(points)
max_job_count_before_translation = ((800 / 15).to_i + 1)
x_translation = [(points.size - max_job_count_before_translation) * 15, 0].max
if x_translation > 0
points.each do |point|
point[0] = point[0] - x_translation
end
end
end
end
end
Loading

0 comments on commit 953f72e

Please sign in to comment.