Skip to content

Commit

Permalink
feat: add --clean option to run:detached command
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelgomesxyz committed Jan 12, 2024
1 parent 6894b26 commit c2f570a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lib/command/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions lib/command/run_detached.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion spec/cpl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c2f570a

Please sign in to comment.