Module: Bellbro::SidekiqUtils

Included in:
Service, Worker
Defined in:
lib/bellbro/sidekiq_utils.rb

Defined Under Namespace

Classes: Job, Queue, Worker

Instance Method Summary collapse

Instance Method Details

#jobsObject



111
112
113
# File 'lib/bellbro/sidekiq_utils.rb', line 111

def jobs
  Job.all_for_class("#{self.name}")
end

#jobs_in_flight_with(arg) ⇒ Object



115
116
117
# File 'lib/bellbro/sidekiq_utils.rb', line 115

def jobs_in_flight_with(arg)
  jobs_with(arg) + workers_with(arg)
end

#jobs_with(arg) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/bellbro/sidekiq_utils.rb', line 119

def jobs_with(arg)
  key   = arg.keys.first
  value = arg.values.first
  jobs.select do |job|
    value == job.send(key)
  end
end

#number_of_active_workers(q_name) ⇒ Object



141
142
143
# File 'lib/bellbro/sidekiq_utils.rb', line 141

def number_of_active_workers(q_name)
  workers_for_queue(q_name).count
end

#workersObject



107
108
109
# File 'lib/bellbro/sidekiq_utils.rb', line 107

def workers
  Worker.all_for_class("#{self.name}")
end

#workers_for_queue(q) ⇒ Object



135
136
137
138
139
# File 'lib/bellbro/sidekiq_utils.rb', line 135

def workers_for_queue(q)
  workers.select do |worker|
    worker.queue == q
  end
end

#workers_with(arg) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/bellbro/sidekiq_utils.rb', line 127

def workers_with(arg)
  key   = arg.keys.first
  value = arg.values.first
  workers.select do |worker|
    value == worker.send(key)
  end
end