Class: Logical::Naf::CreateInfrastructure

Inherits:
Object
  • Object
show all
Includes:
Af::Application::SafeProxy
Defined in:
app/models/logical/naf/create_infrastructure.rb

Instance Method Summary collapse

Constructor Details

#initialize(model_names) ⇒ CreateInfrastructure

Returns a new instance of CreateInfrastructure.



6
7
8
# File 'app/models/logical/naf/create_infrastructure.rb', line 6

def initialize(model_names)
  @model_names = model_names
end

Instance Method Details

#loggerObject



10
11
12
# File 'app/models/logical/naf/create_infrastructure.rb', line 10

def logger
  return af_logger(self.class.name)
end

#workObject



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
# File 'app/models/logical/naf/create_infrastructure.rb', line 14

def work
  first_model = nil
  begin
    @model_names.each do |target_model_name|
      logger.info "target model: #{target_model_name}"
      target_model = target_model_name.constantize rescue nil
      if target_model.nil?
        logger.error "couldn't find target_model #{target_model_name}"
      else
        unless first_model
          target_model.connection.begin_db_transaction
          first_model = target_model
        end
        begin
          logger.info "#{target_model_name}: creating infrastructure"
          target_model.create_infrastructure
          logger.info "#{target_model_name}: creating new partitions"
          target_model.create_new_partitions
          logger.info "#{target_model_name}: done"
        rescue StandardError => e
          logger.error "couldn't create infrastructure for: #{target_model_name}, #{e.message}"
          logger.error e.backtrace.join("\n")
        end
      end
    end
  ensure
    if first_model
      first_model.connection.commit_db_transaction
    end
  end
end