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
|