Class: DeleteCommand

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

Overview

A command object for the delete which will be executed as part of cleaning up.

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.

retrying if an unsuccessful status code is received.

Parameters:

  • client

    The Faraday client which will send the delete message.

  • path

    The path of the resource to be deleted.

  • oks (defaults to: [200,204])

    The response status codes which will be considered successful.

  • attempts (defaults to: 3)

    The number of times this command should be tried,



24
25
26
27
28
29
# File 'lib/brine/cleaner_upper.rb', line 24

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

Instance Method Details

#cleanupObject

Issue the delete based on the parameters provided during construction.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/brine/cleaner_upper.rb', line 35

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