Skip to content

Commit e52fba5

Browse files
committed
allow configuring a per-repo concurrency limit via config
1 parent 73d0f04 commit e52fba5

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

lib/travis/scheduler/config.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Config < Travis::Config
1010
enterprise: false,
1111
github: { api_url: 'https://api.github.com', source_host: 'github.com' },
1212
interval: 2,
13-
limit: { default: 5, by_owner: {}, delegate: {} },
13+
limit: { default: 5, by_owner: {}, by_repo: {}, delegate: {} },
1414
lock: { strategy: :redis, ttl: 150 },
1515
logger: { time_format: false, process_id: false, thread_id: false },
1616
log_level: :info,

lib/travis/scheduler/limit/by_repo.rb

+16-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ByRepo < Struct.new(:context, :owners, :job, :selected, :state, :config)
88
include Helper::Context
99

1010
def enqueue?
11-
unlimited? || by_settings
11+
by_config || unlimited? || by_setting
1212
end
1313

1414
def reports
@@ -17,24 +17,34 @@ def reports
1717

1818
private
1919

20+
def by_config
21+
result = current < max_by_config
22+
report :repo_config, max_by_config unless result
23+
result
24+
end
25+
2026
def unlimited?
21-
max == 0
27+
max_by_setting == 0
2228
end
2329

24-
def by_settings
25-
result = current < max
26-
report :repo_settings, max unless result
30+
def by_setting
31+
result = current < max_by_setting
32+
report :repo_settings, max_by_setting unless result
2733
result
2834
end
2935

3036
def current
3137
state.running_by_repo(repo.id) + selected.select { |j| j.repository_id == repo.id }.size
3238
end
3339

34-
def max
40+
def max_by_setting
3541
repo.settings.maximum_number_of_builds.to_i
3642
end
3743

44+
def max_by_config
45+
config[:limit][:by_repo][repo.slug].to_i
46+
end
47+
3848
def repo
3949
job.repository
4050
end

spec/travis/scheduler/limit_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ def create_jobs(count, attrs = {})
9191
it { expect(report).to include('user svenfuchs: total: 3, running: 0, queueable: 1') }
9292
end
9393

94+
describe 'with a default limit 5 and a repo keychain/config limit 2' do
95+
before { config.limit.default = 5 }
96+
before { config.limit.by_repo = { repo.slug => 2 } }
97+
before { create_jobs(3) }
98+
before { repo.settings.update_attributes!(maximum_number_of_builds: 2) }
99+
before { subject }
100+
101+
it { expect(subject.size).to eq 2 }
102+
it { expect(report).to include('max jobs for repo svenfuchs/gem-release by repo_settings: 2') }
103+
it { expect(report).to include('user svenfuchs: total: 3, running: 0, queueable: 2') }
104+
end
105+
94106
describe 'with a default limit 5 and a repo settings limit 2' do
95107
before { config.limit.default = 5 }
96108
before { create_jobs(3) }

0 commit comments

Comments
 (0)