diff --git a/lib/procodile/status_cli_output.rb b/lib/procodile/status_cli_output.rb index 24946a4..21e2101 100644 --- a/lib/procodile/status_cli_output.rb +++ b/lib/procodile/status_cli_output.rb @@ -36,6 +36,9 @@ def print_header for message in @status['messages'] puts "\e[31m * #{Message.parse(message)}\e[0m" end + if @status['messages'].any? { |message| message['type'] == 'incorrect_quantity' } + puts "\e[33m Run `procodile check_concurrency` to start the missing process(es).\e[0m" + end end end diff --git a/spec/specs/status_cli_output_spec.rb b/spec/specs/status_cli_output_spec.rb new file mode 100644 index 0000000..a564b53 --- /dev/null +++ b/spec/specs/status_cli_output_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' +require 'procodile/status_cli_output' + +describe Procodile::StatusCLIOutput do + def status_with(messages) + { + 'version' => '1.0.27', + 'root' => '/apps/example', + 'supervisor' => {'pid' => 100, 'started_at' => nil}, + 'environment_variables' => {}, + 'messages' => messages + } + end + + let(:incorrect_quantity) do + {'type' => 'incorrect_quantity', 'process' => 'worker', 'current' => 23, 'desired' => 25} + end + + let(:not_running) do + {'type' => 'not_running', 'instance' => 'worker.1', 'status' => 'Failed'} + end + + context "when a process is below its configured quantity" do + subject(:cli) { described_class.new(status_with([incorrect_quantity])) } + + it "still prints the underlying message" do + expect { cli.print_header }.to output(/worker only has 23 instances \(should have 25\)/).to_stdout + end + + it "suggests check_concurrency as the remedy" do + expect { cli.print_header }.to output(/procodile check_concurrency/).to_stdout + end + end + + context "when the only messages are unrelated to quantity" do + subject(:cli) { described_class.new(status_with([not_running])) } + + it "does not suggest check_concurrency" do + expect { cli.print_header }.to_not output(/check_concurrency/).to_stdout + end + end + + context "when there are no messages at all" do + subject(:cli) { described_class.new(status_with([])) } + + it "does not suggest check_concurrency" do + expect { cli.print_header }.to_not output(/check_concurrency/).to_stdout + end + end + + context "when quantity and other messages are both present" do + subject(:cli) { described_class.new(status_with([not_running, incorrect_quantity])) } + + it "suggests check_concurrency only once" do + expect { cli.print_header }.to output(/check_concurrency/).to_stdout + end + end +end