Skip to content

Commit

Permalink
[api] Sum up squeues in WorkerStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
hennevogel committed Oct 19, 2015
1 parent 965ffe0 commit 2cd4395
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/api/app/models/worker_status.rb
Expand Up @@ -29,6 +29,7 @@ def update_workerstatus_cache
ret=ActiveXML.backend.direct_http('/build/_workerstatus')
wdata=Xmlhash.parse(ret)
@mytime = Time.now.to_i
@squeues = Hash.new
Rails.cache.write('workerstatus', ret, expires_in: 3.minutes)
StatusHistory.transaction do
wdata.elements('blocked') do |e|
Expand All @@ -43,12 +44,20 @@ def update_workerstatus_cache
end
end
parse_worker_infos(wdata)
@squeues.each_pair do |key, value|
StatusHistory.create time: @mytime, key: key, value: value
end
end
ret
end

private

def add_squeue(key, value)
@squeues[key] ||= 0
@squeues[key] += value.to_i
end

def parse_daemon_infos(daemon)
return unless daemon['type'] == 'scheduler'
arch = daemon['arch']
Expand All @@ -61,16 +70,13 @@ def parse_daemon_infos(daemon)
end
queue = daemon.get('queue')
return unless queue
StatusHistory.create :time => @mytime, :key => "squeue_high_#{arch}", :value => queue['high'].to_i
StatusHistory.create :time => @mytime, :key => "squeue_next_#{arch}", :value => queue['next'].to_i
StatusHistory.create :time => @mytime, :key => "squeue_med_#{arch}", :value => queue['med'].to_i
StatusHistory.create :time => @mytime, :key => "squeue_low_#{arch}", :value => queue['low'].to_i
%w(high next med low).each { |key| add_squeue("squeue_#{key}_#{arch}", queue[key]) }
end

def parse_worker_infos(wdata)
allworkers = Hash.new
workers = Hash.new
%w{building idle}.each do |state|
%w(building idle).each do |state|
wdata.elements(state) do |e|
id=e['workerid']
if workers.has_key? id
Expand Down
1 change: 1 addition & 0 deletions src/api/test/unit/worker_status_test.rb
Expand Up @@ -3,6 +3,7 @@
class WorkerStatusTest < ActiveSupport::TestCase

test "update cache" do
Suse::Backend.wait_for_scheduler_start
WorkerStatus.new.update_workerstatus_cache
end

Expand Down

0 comments on commit 2cd4395

Please sign in to comment.