diff --git a/CHANGELOG.md b/CHANGELOG.md index a5eba973..fed26485 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ Changes since the last non-beta release. _Please add entries here for your pull requests that have not yet been released._ +- Fixed issue with improper handling of job statuses. Fixed issue with interactive magic string showing and exit code. [PR 177](https://github.com/shakacode/control-plane-flow/pull/177) by [Sergey Tarasov](https://github.com/dzirtusss). + ## [2.0.1] - 2024-05-15 ### Fixed diff --git a/lib/command/run.rb b/lib/command/run.rb index ce6c5f77..8437de20 100644 --- a/lib/command/run.rb +++ b/lib/command/run.rb @@ -395,7 +395,7 @@ def runner_script # rubocop:disable Metrics/MethodLength script += interactive_runner_script if interactive script += - if @log_method == 1 + if @log_method == 1 || @interactive args_join(config.args) else <<~SCRIPT @@ -442,16 +442,22 @@ def print_detached_commands ) end - def resolve_job_status - result = cp.fetch_cron_workload(runner_workload, location: location) - job_details = result&.dig("items")&.find { |item| item["id"] == job } - status = job_details&.dig("status") + def resolve_job_status # rubocop:disable Metrics/MethodLength + loop do + result = cp.fetch_cron_workload(runner_workload, location: location) + job_details = result&.dig("items")&.find { |item| item["id"] == job } + status = job_details&.dig("status") + + Shell.debug("JOB STATUS", status) - case status - when "failed" - ExitCode::ERROR_DEFAULT - when "successful" - ExitCode::SUCCESS + case status + when "active" + sleep 1 + when "successful" + break ExitCode::SUCCESS + else + break ExitCode::ERROR_DEFAULT + end end end diff --git a/spec/command/run_spec.rb b/spec/command/run_spec.rb index bdc272eb..40c69893 100644 --- a/spec/command/run_spec.rb +++ b/spec/command/run_spec.rb @@ -91,21 +91,35 @@ it "clones workload and runs provided command with success", :slow do result = nil - spawn_cpl_command("run", "-a", app, "--entrypoint", "none", "--", "ls") do |it| + spawn_cpl_command("run", "-a", app, "--entrypoint", "none", "--verbose", "--", "ls") do |it| result = it.read_full_output end expect(result).to include("Gemfile") + expect(result).to include("[#{Shell.color('JOB STATUS', :red)}] successful") end it "clones workload and runs provided command with failure", :slow do result = nil - spawn_cpl_command("run", "-a", app, "--entrypoint", "none", "--", "nonexistent") do |it| + spawn_cpl_command("run", "-a", app, "--entrypoint", "none", "--verbose", "--", "nonexistent") do |it| result = it.read_full_output end expect(result).not_to include("Gemfile") + expect(result).to include("[#{Shell.color('JOB STATUS', :red)}] failed") + end + + it "waits for job to finish", :slow do + result = nil + + spawn_cpl_command("run", "-a", app, "--entrypoint", "none", "--verbose", "--", "sleep 10; ls") do |it| + result = it.read_full_output + end + + expect(result).to include("Gemfile") + expect(result).to include("[#{Shell.color('JOB STATUS', :red)}] active") + expect(result).to include("[#{Shell.color('JOB STATUS', :red)}] successful") end end