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; pause is NOT native (needs the fetcher), so it does not advertise :native_pause — the "not enforced" warning still applies.

%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.)



45
46
47
48
49
50
51
52
53
54
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 45

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



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

def dead_set     = ::Sidekiq::DeadSet.new

#fetch_installed?Boolean

Returns:

  • (Boolean)


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

def fetch_installed?  = RoundhouseUi::Pause.fetch_installed?

#nameObject



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

def name = "Sidekiq"

#pause(name) ⇒ Object



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

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

#paused_queuesObject

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



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

def paused_queues     = RoundhouseUi::Pause.paused_set

#process_setObject



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

def process_set  = ::Sidekiq::ProcessSet.new

#push(payload) ⇒ Object



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

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

#queue(name) ⇒ Object



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

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

#queuesObject



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

def queues       = ::Sidekiq::Queue.all

#resume(name) ⇒ Object



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

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

#retry_setObject



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

def retry_set    = ::Sidekiq::RetrySet.new

#scheduled_setObject



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

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.



33
34
35
36
37
38
39
# File 'lib/roundhouse_ui/backends/sidekiq.rb', line 33

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



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

def stats        = ::Sidekiq::Stats.new

#supports?(capability) ⇒ Boolean

Returns:

  • (Boolean)


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

def supports?(capability) = CAPABILITIES.include?(capability)

#work_setObject



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

def work_set     = ::Sidekiq::WorkSet.new