rosa-build/lib/abf_worker/status_inspector.rb

61 lines
1.9 KiB
Ruby
Raw Normal View History

module AbfWorker
class StatusInspector
2013-01-24 10:42:03 +00:00
class << self
def projects_status
2014-01-21 04:51:49 +00:00
Rails.cache.fetch([AbfWorker::StatusInspector, :projects_status], expires_in: 10.seconds) do
result = get_status(:rpm, :publish) { |w, worker| w.to_s =~ /#{worker}_worker_default/ }
nodes = RpmBuildNode.total_statistics
result[:rpm][:workers] += nodes[:systems]
result[:rpm][:build_tasks] += nodes[:busy]
result[:rpm][:other_workers] = nodes[:others]
2014-02-25 22:57:36 +00:00
external_bls = BuildList.for_status(BuildList::BUILD_PENDING).external_nodes(:everything).count
2014-02-25 22:57:36 +00:00
result[:rpm][:default_tasks] += external_bls + count_of_tasks('user_build_')
2014-02-26 15:06:46 +00:00
mass_build_tasks = count_of_tasks('mass_build_')
result[:rpm][:low_tasks] += mass_build_tasks
result[:rpm][:tasks] += external_bls + mass_build_tasks
result
end
2013-01-24 10:42:03 +00:00
end
2014-02-25 22:57:36 +00:00
def count_of_tasks(regexp)
Resque.redis.smembers('queues').
select{ |q| q =~ /#{regexp}/ }.
map{ |q| Resque.redis.llen("queue:#{q}") }.sum
end
2013-01-24 10:42:03 +00:00
def products_status
get_status(:iso) { |w, worker|
str = w.to_s
str =~ /iso_worker/ && str !~ /observer/
}
end
protected
def get_status(*queues)
status = {}
queues.each do |worker|
workers = Resque.workers.select{ |w| yield w, worker }
2013-01-24 11:58:42 +00:00
status[worker] = status_of_worker workers, worker
2013-01-24 10:42:03 +00:00
end
status
end
2013-01-24 11:58:42 +00:00
def status_of_worker(workers, worker)
2013-01-24 10:42:03 +00:00
redis, key = Resque.redis, "queue:#{worker}_worker"
default_tasks, tasks = redis.llen("#{key}_default"), redis.llen(key)
2013-01-24 11:58:42 +00:00
{
2014-01-21 04:51:49 +00:00
workers: workers.count,
build_tasks: workers.select{ |w| w.working? }.count,
default_tasks: default_tasks,
low_tasks: tasks,
tasks: (default_tasks + tasks)
}
end
2013-01-24 10:42:03 +00:00
end
end
2014-01-21 04:51:49 +00:00
end