Skip to content

Commit 0cce695

Browse files
committed
add stats about waiting jobs
1 parent 5722ab5 commit 0cce695

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

lib/travis/scheduler/limit/jobs.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ module Limit
88
max: 'max jobs for %s by %s: %s',
99
max_plan: 'max jobs for %s by %s: %s (%s)',
1010
max_stage: 'jobs for %s limited at stage: %s (queueable: %s)',
11-
summary: '%s: total: %s, running: %s, queueable: %s'
11+
summary: '%s: total: %s, running: %s, queueable: %s',
12+
stats: 'jobs waiting for %s: %s'
1213
}
1314

1415
class Jobs < Struct.new(:context, :owners)
@@ -26,6 +27,7 @@ def run
2627
unleak_queueables if ENV['UNLEAK_QUEUEABLE_JOBS']
2728
check_all
2829
report summary
30+
report stats if waiting.any?
2931
end
3032

3133
def reports
@@ -77,11 +79,7 @@ def check(job)
7779
end
7880

7981
def enqueue?(job)
80-
limits_for(job).map do |limit|
81-
result = limit.enqueue?
82-
# report *limit.reports
83-
result
84-
end.inject(&:&)
82+
limits_for(job).map(&:enqueue?).inject(&:&)
8583
end
8684

8785
def limits_for(job)
@@ -92,10 +90,20 @@ def summary
9290
MSGS[:summary] % [owners.to_s, queueable.size, state.running_by_owners, selected.size]
9391
end
9492

93+
def stats
94+
jobs = waiting.group_by(&:repository)
95+
stats = jobs.map { |repo, jobs| [repo.slug, jobs.size].join('=') }
96+
MSGS[:stats] % [owners.key, stats.join(', ')]
97+
end
98+
9599
def report(*reports)
96100
self.reports.concat(reports).uniq!
97101
end
98102

103+
def waiting
104+
queueable - selected
105+
end
106+
99107
def queueable
100108
@queueable ||= Job.by_owners(owners.all).queueable.to_a
101109
end

spec/travis/scheduler/limit_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def create_jobs(count, attrs = {})
3838
it { expect(subject.size).to eq 2 }
3939
it { expect(report).to include('max jobs for user svenfuchs by boost: 2') }
4040
it { expect(report).to include('user svenfuchs: total: 3, running: 0, queueable: 2') }
41+
it { expect(report).to include('jobs waiting for svenfuchs: svenfuchs/gem-release=1') }
4142
end
4243

4344
describe 'with a subscription limit 1' do

0 commit comments

Comments
 (0)