Class: Brine::CleaningUp::DeleteCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/brine/cleaning_up.rb

Overview

Capture the delete command which will be executed as part of cleaning up.

The command will be retried a specified number of times if an unsuccessful status code is received.

Instance Method Summary collapse

Constructor Details

#initialize(client, path, oks: [200,204], attempts: 3) ⇒ DeleteCommand

Construct a command with the required paramters to perform the delete.

Parameters:

  • client (Faraday::Connection, #delete)

    Provide the Faraday client which will send the delete message.

  • path (String)

    Specify the path of the resource to be deleted.

  • oks (Array<Integer>) (defaults to: [200,204])

    Indicate response status codes which should be considered successful) (defaults to [200,204]).

  • attempts (Integer) (defaults to: 3)

    Specify the number of times this command should be tried (defaults to 3).

[View source]

41
42
43
44
45
46
# File 'lib/brine/cleaning_up.rb', line 41

def initialize(client, path, oks: [200,204], attempts: 3)
  @client = client
  @path = path
  @oks = oks
  @attempts = attempts
end

Instance Method Details

#cleanupBoolean

Issue the delete based on the parameters provided during construction.

Returns:

  • (Boolean)

    Return true if a successful response is obtained, otherwise false.

[View source]

53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/brine/cleaning_up.rb', line 53

def cleanup
  for _ in 1..@attempts
    begin
      resp=@client.delete(@path)
      return true if @oks.include?(resp.status)
    rescue Exception => ex
      STDERR.puts "WARNING: #{ex}"
    end
  end
  STDERR.puts "ERROR: Could not DELETE #{@path}"
  false
end