Class: Spurious::Server::State::Delete

Inherits:
Base
  • Object
show all
Defined in:
lib/spurious/server/state/delete.rb

Instance Attribute Summary

Attributes inherited from Base

#config, #connection

Instance Method Summary collapse

Methods inherited from Base

#connection_timeouts

Constructor Details

#initialize(connection, config) ⇒ Delete

Returns a new instance of Delete.



10
11
12
13
# File 'lib/spurious/server/state/delete.rb', line 10

def initialize(connection, config)
  super
  connection_timeouts 2, 600, 600
end

Instance Method Details

#execute!Object



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/spurious/server/state/delete.rb', line 15

def execute!
  containers = spurious_containers.length - 1

  spurious_containers.each_with_index do |container, index|
    container_name   = container.json["Name"].gsub('/', '')
    container_config = config.for(container_name)
    container_meta   = container.json

    remove_container = Proc.new do
      send "Removing #{container_name}", :debug
      container.delete(:force => true)

      unless container_config[:ignore] && container_config[:ignore][:delete]
        image = container_config[:image]

        Docker::Image.get(container_meta["Image"]).tap do |image|
          image.remove(:force => true)
        end
      end

      index_to_check = index + 1
      containers == index_to_check
    end

    EM.defer(remove_container, operation_complete)

  end
end

#operation_completeObject



44
45
46
47
48
# File 'lib/spurious/server/state/delete.rb', line 44

def operation_complete
  Proc.new do |complete|
    send("5 containers successfully removed", :info, true, :green) if complete
  end
end