Class: Service::Containers

Inherits:
Object
  • Object
show all
Defined in:
app/models/service/containers.rb

Class Method Summary collapse

Class Method Details

.destroy_wizard_state(wizard_state) ⇒ Object



33
34
35
36
# File 'app/models/service/containers.rb', line 33

def self.destroy_wizard_state(wizard_state)
  wizard_state.destroy
  DockerContainerWizardState.destroy_all(["updated_at < ?", (Time.now - 24.hours)])
end

.start_container(container) ⇒ Object



27
28
29
30
31
# File 'app/models/service/containers.rb', line 27

def self.start_container(container)
  started = container.compute_resource.create_container(container.parametrize)
  container.uuid = started.id if started
  started
end

.start_container!(wizard_state) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/service/containers.rb', line 3

def self.start_container!(wizard_state)
  ActiveRecord::Base.transaction do
    container = Container.new(wizard_state.container_attributes) do |r|
      # eagerly load environment variables
      state = DockerContainerWizardState.includes(:environment => [:environment_variables])
        .find(wizard_state.id)
      state.environment_variables.each do |environment_variable|
        r.environment_variables.build :name     => environment_variable.name,
                                      :value    => environment_variable.value,
                                      :priority => environment_variable.priority
      end
    end
    Taxonomy.enabled_taxonomies.each do |taxonomy|
      container.send(:"#{taxonomy}=", wizard_state.preliminary.send(:"#{taxonomy}"))
    end

    fail ActiveRecord::Rollback unless start_container(container)

    container.save!
    destroy_wizard_state(wizard_state)
    container
  end
end