Class: Superbot::Cloud::CLI::Webdriver::DeleteCommand

Inherits:
BaseCommand show all
Defined in:
lib/superbot/cloud/cli/webdriver/delete_command.rb

Instance Method Summary collapse

Methods inherited from LoginRequiredCommand

#run, run

Methods included from Validations

#require_login

Instance Method Details

#delete_sessionObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/superbot/cloud/cli/webdriver/delete_command.rb', line 15

def delete_session
  if all?
    webdriver_sessions = Superbot::Cloud::Api.request(
      :webdriver_session_list,
      params: { organization_name: organization, 'aasm_state[]': %w[idle proxying] }
    ).fetch(:webdriver_sessions, [])

    abort "All sessions are finished" if webdriver_sessions.empty?

    @session_id_list = webdriver_sessions&.map { |session| session[:session_id] }
  elsif session_id_list.empty?
    signal_usage_error "parameter SESSION_ID is required"
  end

  session_id_list.each do |session_id|
    Superbot::Cloud::Api.request(
      :delete_webdriver_session,
      params: {
        session_id: session_id,
        organization_name: organization
      }
    )

    puts "Webdriver session #{session_id} removal has been requested."
  rescue SystemExit
    p # skip to next webdriver session
  end
end

#executeObject



11
12
13
# File 'lib/superbot/cloud/cli/webdriver/delete_command.rb', line 11

def execute
  delete_session
end