Class: Command::Run

Inherits:
Base
  • Object
show all
Defined in:
lib/command/run.rb

Constant Summary collapse

NAME =
"run"
USAGE =
"run COMMAND"
REQUIRES_ARGS =
true
DEFAULT_ARGS =
["bash"].freeze
OPTIONS =
[
  app_option(required: true),
  image_option,
  workload_option,
  use_local_token_option
].freeze
DESCRIPTION =
"Runs one-off **_interactive_** replicas (analog of `heroku run`)"
LONG_DESCRIPTION =
"- Runs one-off **_interactive_** replicas (analog of `heroku run`)\n- Uses `Standard` workload type and `cpln exec` as the execution method, with CLI streaming\n- May not work correctly with tasks that last over 5 minutes (there's a Control Plane scaling bug at the moment)\n\n> **IMPORTANT:** Useful for development where it's needed for interaction, and where network connection drops and\n> task crashing are tolerable. For production tasks, it's better to use `cpl run:detached`.\n"
EXAMPLES =
"```sh\n# Opens shell (bash by default).\ncpl run -a $APP_NAME\n\n# Runs command, displays output, and exits shell.\ncpl run ls / -a $APP_NAME\ncpl run rails db:migrate:status -a $APP_NAME\n\n# Runs command and keeps shell open.\ncpl run rails c -a $APP_NAME\n\n# Uses a different image (which may not be promoted yet).\ncpl run rails db:migrate -a $APP_NAME --image appimage:123 # Exact image name\ncpl run rails db:migrate -a $APP_NAME --image latest       # Latest sequential image\n\n# Uses a different workload\ncpl run bash -a $APP_NAME -w other-workload\n\n# Overrides remote CPLN_TOKEN env variable with local token.\n# Useful when need superuser rights in remote container\ncpl run bash -a $APP_NAME --use-local-token\n```\n"

Constants inherited from Base

Base::HIDE, Base::NO_IMAGE_AVAILABLE

Instance Attribute Summary collapse

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

all_commands, all_options, all_options_by_key_name, app_option, #args_join, commit_option, #cp, #ensure_workload_deleted, image_option, #initialize, #latest_image, #latest_image_from, #latest_image_next, org_option, #perform, #progress, skip_confirm_option, #step, upstream_token_option, use_local_token_option, version_option, #wait_for, #wait_for_replica, #wait_for_workload, workload_option

Constructor Details

This class inherits a constructor from Command::Base

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



49
50
51
# File 'lib/command/run.rb', line 49

def container
  @container
end

#locationObject (readonly)

Returns the value of attribute location.



49
50
51
# File 'lib/command/run.rb', line 49

def location
  @location
end

#one_offObject (readonly)

Returns the value of attribute one_off.



49
50
51
# File 'lib/command/run.rb', line 49

def one_off
  @one_off
end

#workloadObject (readonly)

Returns the value of attribute workload.



49
50
51
# File 'lib/command/run.rb', line 49

def workload
  @workload
end

Instance Method Details

#callObject



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/command/run.rb', line 51

def call
  @location = config[:default_location]
  @workload = config.options["workload"] || config[:one_off_workload]
  @one_off = "#{workload}-run-#{rand(1000..9999)}"

  clone_workload
  wait_for_workload(one_off)
  wait_for_replica(one_off, location)
  run_in_replica
ensure
  ensure_workload_deleted(one_off)
end