Class: RoundhouseUi::Backends::Sidekiq

Inherits:
Object
  • Object
show all
Defined in:
lib/roundhouse_ui/backends/sidekiq.rb

Overview

The Sidekiq implementation of the Roundhouse backend port. It is a thin seam over Sidekiq's own API objects — controllers ask the backend for a "set" or "stats" instead of naming Sidekiq::* directly, so a second backend (Solid Queue) can supply duck-typed equivalents without touching controllers or views.

Deliberately thin for now: each method returns the same Sidekiq object the controllers used before, so this refactor changes no behavior. The contract (what a "set" / "entry" must respond to) will be firmed up as the Solid Queue backend is built against it.

Constant Summary collapse

CAPABILITIES =

Capabilities let the UI hide what a backend can't do. Sidekiq supports all the sets/views. On OSS Sidekiq pause is NOT native (it needs our fetcher), so :native_pause is withheld and the "not enforced" warning applies — but Sidekiq Pro ships its own enforced pause, so there it is advertised and the warning drops away.

%i[retries dead scheduled busy workers redis capsules].freeze

Instance Method Summary collapse

Instance Method Details

#busyObject

Currently-executing jobs, normalized to the Busy view's shape. (This normalization used to live in BusyController; it belongs to the backend.)



52
53
54
55
56
57
58
59
60
61
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 52

def busy
  ::Sidekiq::WorkSet.new.map do |process_id, tid, work|
    if work.respond_to?(:queue) # Sidekiq 7+: Sidekiq::Work struct
      { process: process_id, tid: tid, queue: work.queue, run_at: work.run_at, job: work.job }
    else                         # Sidekiq 6.x: a plain Hash
      { process: process_id, tid: tid, queue: work["queue"],
        run_at: Time.at(work["run_at"]), job: ::Sidekiq::JobRecord.new(work["payload"]) }
    end
  end
end

#dead_setObject



33
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 33

def dead_set     = ::Sidekiq::DeadSet.new

#fetch_installed?Boolean

Returns:

  • (Boolean)


67
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 67

def fetch_installed?  = RoundhouseUi::Pause.fetch_installed?

#nameObject



14
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 14

def name = "Sidekiq"

#pause(name) ⇒ Object



65
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 65

def pause(name)       = RoundhouseUi::Pause.pause!(name)

#paused_queuesObject

--- pause (via the opt-in Roundhouse fetcher; not native) ---



64
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 64

def paused_queues     = RoundhouseUi::Pause.paused_set

#process_setObject



36
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 36

def process_set  = ::Sidekiq::ProcessSet.new

#push(payload) ⇒ Object



48
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 48

def push(payload) = ::Sidekiq::Client.push(payload)

#queue(name) ⇒ Object



31
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 31

def queue(name)  = ::Sidekiq::Queue.new(name)

#queuesObject



30
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 30

def queues       = ::Sidekiq::Queue.all

#resume(name) ⇒ Object



66
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 66

def resume(name)      = RoundhouseUi::Pause.unpause!(name)

#retry_setObject



32
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 32

def retry_set    = ::Sidekiq::RetrySet.new

#scheduled_setObject



34
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 34

def scheduled_set = ::Sidekiq::ScheduledSet.new

#set(kind) ⇒ Object

The job set a given UI section maps to (used by the job-detail page). Lazy — only builds the requested set.



40
41
42
43
44
45
46
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 40

def set(kind)
  case kind.to_s
  when "dead"      then dead_set
  when "retry"     then retry_set
  when "scheduled" then scheduled_set
  end
end

#statsObject



29
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 29

def stats        = ::Sidekiq::Stats.new

#supports?(capability) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 23

def supports?(capability)
  return RoundhouseUi::Pause.native? if capability == :native_pause

  CAPABILITIES.include?(capability)
end

#work_setObject



35
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 35

def work_set     = ::Sidekiq::WorkSet.new