diff --git a/docs/commands.md b/docs/commands.md index 9bb48a12..edf29cd7 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -375,6 +375,7 @@ cpl run:cleanup -a $APP_NAME - Implemented with only async execution methods, more suitable for production tasks - Has alternative log fetch implementation with only JSON-polling and no WebSockets - Less responsive but more stable, useful for CI tasks +- Deletes the workload when disconnecting by default (can be disabled with `--no-clean` - the workload will still self-delete when finishing) ```sh cpl run:detached rails db:prepare -a $APP_NAME diff --git a/lib/command/base.rb b/lib/command/base.rb index 6d2e950f..0cb45090 100644 --- a/lib/command/base.rb +++ b/lib/command/base.rb @@ -221,6 +221,18 @@ def self.trace_option(required: false) } end + def self.clean_option(required: false) + { + name: :clean, + params: { + desc: "Deletes workload when disconnecting", + type: :boolean, + required: required, + default: true + } + } + end + def self.all_options methods.grep(/_option$/).map { |method| send(method.to_s) } end diff --git a/lib/command/run_detached.rb b/lib/command/run_detached.rb index cec1629f..35c6bb8a 100644 --- a/lib/command/run_detached.rb +++ b/lib/command/run_detached.rb @@ -10,7 +10,8 @@ class RunDetached < Base # rubocop:disable Metrics/ClassLength image_option, workload_option, location_option, - use_local_token_option + use_local_token_option, + clean_option ].freeze DESCRIPTION = "Runs one-off **_non-interactive_** replicas (close analog of `heroku run:detached`)" LONG_DESCRIPTION = <<~DESC @@ -19,6 +20,7 @@ class RunDetached < Base # rubocop:disable Metrics/ClassLength - Implemented with only async execution methods, more suitable for production tasks - Has alternative log fetch implementation with only JSON-polling and no WebSockets - Less responsive but more stable, useful for CI tasks + - Deletes the workload when disconnecting by default (can be disabled with `--no-clean` - the workload will still self-delete when finishing) DESC EXAMPLES = <<~EX ```sh @@ -59,7 +61,7 @@ def call # rubocop:disable Metrics/MethodLength wait_for_workload(one_off) show_logs_waiting ensure - if cp.fetch_workload(one_off) + if config.options[:clean] && cp.fetch_workload(one_off) progress.puts ensure_workload_deleted(one_off) end diff --git a/spec/cpl_spec.rb b/spec/cpl_spec.rb index 31e7cd40..986c7f58 100644 --- a/spec/cpl_spec.rb +++ b/spec/cpl_spec.rb @@ -37,7 +37,9 @@ args = [option_key_name, option_value] end - allow(Config).to receive(:new).with([], { option[:name].to_sym => option_value }, []).and_call_original + allow(Config).to receive(:new) + .with([], a_hash_including(option[:name].to_sym => option_value), []) + .and_call_original allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") # rubocop:disable RSpec/AnyInstance expect_any_instance_of(Command::Test).to receive(:call) # rubocop:disable RSpec/AnyInstance