Class: Spurious::Server::State::Init
- Defined in:
- lib/spurious/server/state/init.rb
Instance Attribute Summary collapse
-
#completed_containers ⇒ Object
Returns the value of attribute completed_containers.
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Spurious::Server::State::Base
Instance Attribute Details
#completed_containers ⇒ Object
Returns the value of attribute completed_containers.
11 12 13 |
# File 'lib/spurious/server/state/init.rb', line 11 def completed_containers @completed_containers end |
Instance Method Details
#execute! ⇒ Object
13 14 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/spurious/server/state/init.rb', line 13 def execute! this = self completed_containers = 0 app_config.each do |name, | = { 'fromImage' => [:image]} ['Env'] = [:env] unless [:env].nil? container_operation = Proc.new do begin this.send "Creating container with name: #{name}" Docker::Container.create("name" => name, "Image" => [:image]) rescue Exception => e case e. when /409 Conflict/ this.error "Container with name: #{name} already exists" else this.error "Error creating container: #{e.message}" end end end container_callback = Proc.new do completed_containers = completed_containers + 1 this.send("#{config.app.length} containers successfully initialized", true) if completed_containers == app_config.length end image_operation = Proc.new do begin this.send "Pulling #{name} from the public repo..." Docker::Image.create() rescue Exception => e this.error "Error pulling down image: #{e.message}" end end image_callback = Proc.new do EM.add_timer(1) do EM.defer(container_operation, container_callback) end end EM.add_timer(1) do EM.defer(image_operation, image_callback) end end end |