Class: Process::Naf::Janitor

Inherits:
Application
  • Object
show all
Defined in:
app/models/process/naf/janitor.rb

Constant Summary collapse

ASSIGNMENTS =
{
  creates: ::Naf::JanitorialCreateAssignment,
  archives: ::Naf::JanitorialArchiveAssignment,
  drops: ::Naf::JanitorialDropAssignment
}
ASSIGNMENT_TYPES =
ASSIGNMENTS.keys

Instance Method Summary collapse

Instance Method Details

#assignments_to_process(assignment_type = ::Naf::JanitorialAssignment) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'app/models/process/naf/janitor.rb', line 55

def assignments_to_process(assignment_type = ::Naf::JanitorialAssignment)
  if @assignments == :all
    return assignment_type.all.order('type,assignment_order')
  elsif @assignments == :all_enabled
    return assignment_type.where('enabled').order('type,assignment_order')
  else
    return [*assignment_type.find(@assignments).order('type,assignment_order')]
  end
end

#post_command_line_parsingObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/models/process/naf/janitor.rb', line 65

def post_command_line_parsing
  if @list_assignments
    assignment_list = [["ID", "TYPE", "ORDER", "MODEL"]]
    [:creates, :archives, :drops].each do |assignment_type_name|
      unless @assignment_types.include? assignment_type_name
        next
      end
      assignment_type_processor = ASSIGNMENTS[assignment_type_name]
      assignments_to_process(assignment_type_processor).each do |a|
        assignment_list << [a.id.to_s, a.type.to_s, a.assignment_order.to_s, a.model_name]
      end
    end
    puts self.class.columnized(assignment_list).join("\n")
    exit 0
  end
  unless @create_infrastructure.blank?
    logger.info "creating infrastructure: #{@create_infrastructure.inspect}"
    ::Logical::Naf::CreateInfrastructure.new(@create_infrastructure).work
    exit 0
  end
  super
end

#workObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/models/process/naf/janitor.rb', line 88

def work
  logger.info "Janitor STARTED -- let's see what there is to do."

  # assignment types are handled in this order
  [:creates, :archives, :drops].each do |assignment_type_name|
    unless @assignment_types.include? assignment_type_name
      next
    end
    assignment_type_processor = ASSIGNMENTS[assignment_type_name]
    assignments_to_process(assignment_type_processor).each do |assignment|
      logger.info "#{assignment_type_processor}: #{assignment.model_name} START"
      target_model = assignment.target_model
      if target_model.nil?
        logger.alarm "#{assignment_type_processor}: failed to instantiate target model: #{assignment.model_name}"
        next
      end
      begin
        assignment_type_processor.new.do_janitorial_work(target_model) unless @no_writes
      rescue StandardError => e
        logger.alarm "failed to use #{assignment_type_processor} for partitions model: #{assignment.model_name}"
        logger.alarm e
      end
      logger.info "#{assignment_type_processor}: #{assignment.model_name} DONE"
    end
  end

  logger.info "janitor DONE"
end