Skip to content

Commit 67c1a82

Browse files
committed
Pick default gunicorn workers from non-legacy fact
While the documentation for the core fact `processors.count` states that it is an _integer_ already, the previous behavior was to silently treat a missing fact as a processor count of zero, via `NilClass#to_i`. This does not happen in FacterDB entries for supported os, but the spec still mirrors the conversion done by the template.
1 parent 91d351e commit 67c1a82

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

manifests/gunicorn.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
String[1] $template = 'python/gunicorn.erb',
5656
Array $args = [],
5757
) {
58+
$processor_count = fact('processors.count')
59+
5860
if $manage_config_dir {
5961
file { $config_dir:
6062
ensure => directory,

spec/defines/gunicorn_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
context 'configures test app with default parameter values' do
1414
let(:params) { { dir: '/srv/testapp' } }
1515
let(:expected_workers) do
16+
# manifests/gunicorn.pp
17+
processor_count = facts.dig(:processors, 'count')
18+
1619
# templates/gunicorn.erb
17-
(facts[:processorcount].to_i * 2) + 1
20+
(processor_count.to_i * 2) + 1
1821
end
1922

2023
it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--log-level=error}) }

templates/gunicorn.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CONFIG = {
3939
<% if @workers -%>
4040
'--workers=<%= @workers %>',
4141
<% else -%>
42-
'--workers=<%= @processorcount.to_i*2 + 1 %>',
42+
'--workers=<%= @processor_count.to_i*2 + 1 %>',
4343
<% end -%>
4444
'--timeout=<%= @timeout %>',
4545
<% if @access_log_format -%>

0 commit comments

Comments
 (0)