Module: SolidQueueMonitor::WorkersHelper
- Defined in:
- app/helpers/solid_queue_monitor/workers_helper.rb
Constant Summary collapse
- HEARTBEAT_STALE_THRESHOLD =
5.minutes
- HEARTBEAT_DEAD_THRESHOLD =
10.minutes
Instance Method Summary collapse
- #worker_heartbeat(heartbeat_at) ⇒ Object
- #worker_hostname(process) ⇒ Object
- #worker_jobs_processing(process, claimed_counts:, claimed_jobs:) ⇒ Object
- #worker_kind_badge(kind) ⇒ Object
- #worker_metadata(process) ⇒ Object
- #worker_queues(process) ⇒ Object
- #worker_row_class(process) ⇒ Object
- #worker_status(process) ⇒ Object
- #worker_status_badge(status) ⇒ Object
Instance Method Details
#worker_heartbeat(heartbeat_at) ⇒ Object
55 56 57 58 59 |
# File 'app/helpers/solid_queue_monitor/workers_helper.rb', line 55 def worker_heartbeat(heartbeat_at) return '-' unless heartbeat_at tag.span("#{time_ago_in_words(heartbeat_at)} ago", title: heartbeat_at.strftime('%Y-%m-%d %H:%M:%S')) end |
#worker_hostname(process) ⇒ Object
36 37 38 |
# File 'app/helpers/solid_queue_monitor/workers_helper.rb', line 36 def worker_hostname(process) process.hostname || (process)['hostname'] || '-' end |
#worker_jobs_processing(process, claimed_counts:, claimed_jobs:) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/solid_queue_monitor/workers_helper.rb', line 65 def worker_jobs_processing(process, claimed_counts:, claimed_jobs:) count = claimed_counts[process.id] || 0 return tag.span('Idle', class: 'jobs-idle') if count.zero? jobs = claimed_jobs[process.id] || [] job_names = jobs.map(&:class_name).uniq.first(3) tooltip = jobs.first(10).map { |job| "#{job.class_name} (ID: #{job.id})" }.join("\n") label = "#{count} job#{'s' if count > 1}" names = "(#{job_names.join(', ')}#{'...' if jobs.length > 3})" tag.span(class: 'jobs-processing', title: tooltip) do safe_join([label, tag.span(names, class: 'job-names')], ' ') end end |
#worker_kind_badge(kind) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/solid_queue_monitor/workers_helper.rb', line 26 def worker_kind_badge(kind) badge_class = case kind when 'Worker' then 'kind-worker' when 'Dispatcher' then 'kind-dispatcher' when 'Scheduler' then 'kind-scheduler' else 'kind-other' end tag.span(kind, class: class_names('kind-badge', badge_class)) end |
#worker_metadata(process) ⇒ Object
80 81 82 83 84 85 86 |
# File 'app/helpers/solid_queue_monitor/workers_helper.rb', line 80 def (process) return {} unless process. process..is_a?(String) ? JSON.parse(process.) : process. rescue JSON::ParserError {} end |
#worker_queues(process) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/helpers/solid_queue_monitor/workers_helper.rb', line 40 def worker_queues(process) queues = (process)['queues'] return '-' if queues.nil? return tag.code(queues == '*' ? 'All Queues' : queues, class: 'queue-tag') if queues.is_a?(String) return '-' if queues.empty? if queues.length <= 3 safe_join(queues.map { |queue| tag.code(queue, class: 'queue-tag') }, ' ') else visible = safe_join(queues.first(2).map { |queue| tag.code(queue, class: 'queue-tag') }, ' ') safe_join([visible, tag.span("+#{queues.length - 2} more", class: 'queue-more')], ' ') end end |
#worker_row_class(process) ⇒ Object
18 19 20 21 22 23 24 |
# File 'app/helpers/solid_queue_monitor/workers_helper.rb', line 18 def worker_row_class(process) case worker_status(process) when :dead then 'worker-dead' when :stale then 'worker-stale' else '' end end |
#worker_status(process) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'app/helpers/solid_queue_monitor/workers_helper.rb', line 8 def worker_status(process) return :dead unless process.last_heartbeat_at time_since_heartbeat = Time.current - process.last_heartbeat_at return :dead if time_since_heartbeat > HEARTBEAT_DEAD_THRESHOLD return :stale if time_since_heartbeat > HEARTBEAT_STALE_THRESHOLD :healthy end |
#worker_status_badge(status) ⇒ Object
61 62 63 |
# File 'app/helpers/solid_queue_monitor/workers_helper.rb', line 61 def worker_status_badge(status) tag.span(status.to_s.capitalize, class: "status-badge status-#{status}") end |