Skip to content

Commit dbe83ab

Browse files
Fix issue where ps:wait command hangs forever if workloads are suspended (#198)
1 parent 3c4f5da commit dbe83ab

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Changes since the last non-beta release.
1414

1515
_Please add entries here for your pull requests that have not yet been released._
1616

17+
### Fixed
18+
19+
- Fixed issue where `ps:wait` command hangs forever if workloads are suspended. [PR 198](https://github.com/shakacode/control-plane-flow/pull/198) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
20+
1721
### Added
1822

1923
- Added a timeout for `run` jobs (6 hours by default, but configurable through `runner_job_timeout` in `controlplane.yml`). [PR 194](https://github.com/shakacode/control-plane-flow/pull/194) by [Rafael Gomes](https://github.com/rafaelgomesxyz).

lib/command/ps_wait.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ class PsWait < Base
2222
```
2323
EX
2424

25-
def call
25+
def call # rubocop:disable Metrics/MethodLength
2626
@workloads = [config.options[:workload]] if config.options[:workload]
2727
@workloads ||= config[:app_workloads] + config[:additional_workloads]
2828

2929
@workloads.reverse_each do |workload|
30-
step("Waiting for workload '#{workload}' to be ready", retry_on_failure: true) do
31-
cp.workload_deployments_ready?(workload, location: config.location, expected_status: true)
30+
if cp.workload_suspended?(workload)
31+
progress.puts("Workload '#{workload}' is suspended. Skipping...")
32+
else
33+
step("Waiting for workload '#{workload}' to be ready", retry_on_failure: true) do
34+
cp.workload_deployments_ready?(workload, location: config.location, expected_status: true)
35+
end
3236
end
3337
end
3438
end

lib/core/controlplane.rb

+5
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ def set_workload_suspend(workload, value)
256256
api.update_workload(org: org, gvc: gvc, workload: workload, data: data)
257257
end
258258

259+
def workload_suspended?(workload)
260+
details = fetch_workload!(workload)
261+
details["spec"]["defaultOptions"]["suspend"]
262+
end
263+
259264
def workload_force_redeployment(workload)
260265
cmd = "cpln workload force-redeployment #{workload} #{gvc_org}"
261266
perform!(cmd)

spec/command/ps_wait_spec.rb

+26-10
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,35 @@
1010
run_cpl_command!("ps:restart", "-a", app)
1111
end
1212

13-
it "waits for all workloads to be ready", :slow do
14-
result = run_cpl_command("ps:wait", "-a", app)
13+
context "when no workloads are suspended" do
14+
it "waits for all workloads to be ready", :slow do
15+
result = run_cpl_command("ps:wait", "-a", app)
1516

16-
expect(result[:status]).to eq(0)
17-
expect(result[:stderr]).to match(/Waiting for workload 'rails' to be ready[.]+? done!/)
18-
expect(result[:stderr]).to match(/Waiting for workload 'postgres' to be ready[.]+? done!/)
17+
expect(result[:status]).to eq(0)
18+
expect(result[:stderr]).to match(/Waiting for workload 'rails' to be ready[.]+? done!/)
19+
expect(result[:stderr]).to match(/Waiting for workload 'postgres' to be ready[.]+? done!/)
20+
end
21+
22+
it "waits for specific workload to be ready", :slow do
23+
result = run_cpl_command("ps:wait", "-a", app, "--workload", "rails")
24+
25+
expect(result[:status]).to eq(0)
26+
expect(result[:stderr]).to match(/Waiting for workload 'rails' to be ready[.]+? done!/)
27+
expect(result[:stderr]).not_to include("postgres")
28+
end
1929
end
2030

21-
it "waits for specific workload to be ready", :slow do
22-
result = run_cpl_command("ps:wait", "-a", app, "--workload", "rails")
31+
context "when some workloads are suspended" do
32+
before do
33+
run_cpl_command!("ps:stop", "-a", app, "--workload", "rails")
34+
end
35+
36+
it "skips suspended workloads", :slow do
37+
result = run_cpl_command("ps:wait", "-a", app)
2338

24-
expect(result[:status]).to eq(0)
25-
expect(result[:stderr]).to match(/Waiting for workload 'rails' to be ready[.]+? done!/)
26-
expect(result[:stderr]).not_to include("postgres")
39+
expect(result[:status]).to eq(0)
40+
expect(result[:stderr]).to include("Workload 'rails' is suspended")
41+
expect(result[:stderr]).to match(/Waiting for workload 'postgres' to be ready[.]+? done!/)
42+
end
2743
end
2844
end

0 commit comments

Comments
 (0)