Module: Aptible::CLI::Helpers::Operation
- Defined in:
- lib/aptible/cli/helpers/operation.rb
Constant Summary collapse
- POLL_INTERVAL =
1
Instance Method Summary collapse
- #attach_to_operation_logs(operation) ⇒ Object
- #poll_for_success(operation) ⇒ Object
- #wait_for_completion(operation) ⇒ Object
Instance Method Details
#attach_to_operation_logs(operation) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/aptible/cli/helpers/operation.rb', line 23 def attach_to_operation_logs(operation) host = operation.resource.account.bastion_host port = operation.resource.account.dumptruck_port set_env('ACCESS_TOKEN', fetch_token) set_env('APTIBLE_OPERATION', operation.id.to_s) set_env('APTIBLE_CLI_COMMAND', 'oplog') opts = " -o 'SendEnv=*' -o StrictHostKeyChecking=no " \ '-o UserKnownHostsFile=/dev/null -o LogLevel=quiet' result = Kernel.system "ssh #{opts} -p #{port} root@#{host}" # If Dumptruck is down, fall back to polling for success. If the # operation failed, poll_for_success will immediately fall through to # the error message. poll_for_success(operation) unless result end |
#poll_for_success(operation) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/aptible/cli/helpers/operation.rb', line 9 def poll_for_success(operation) wait_for_completion operation return if operation.status == 'succeeded' fail Thor::Error, 'Operation failed. Please contact [email protected]' end |
#wait_for_completion(operation) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/aptible/cli/helpers/operation.rb', line 16 def wait_for_completion(operation) while %w(queued running).include? operation.status sleep 1 operation.get end end |