Class: Fme::EnterpriseBus::Jobs::CleanupJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
lib/fme/enterprise_bus/jobs/cleanup_job.rb

Instance Method Summary collapse

Instance Method Details

#args_to_destroyObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/fme/enterprise_bus/jobs/cleanup_job.rb', line 15

def args_to_destroy
  built_arguments = {
    column_name => @message.assembly_id
  }

  if organization_id.present?
    built_arguments[:organization_id] = organization_id
  end
  built_arguments
end

#column_nameObject



37
38
39
# File 'lib/fme/enterprise_bus/jobs/cleanup_job.rb', line 37

def column_name
  ActiveRecord::Base.send(:sanitize_sql_for_conditions, "#{@message.assembly_name.underscore}_id")
end

#organization_idObject



26
27
28
# File 'lib/fme/enterprise_bus/jobs/cleanup_job.rb', line 26

def organization_id
  @message.payload.with_indifferent_access.dig('organization_id')
end

#perform(message) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/fme/enterprise_bus/jobs/cleanup_job.rb', line 7

def perform(message)
  @message = message
  Rails.logger.info "cleaning up #{column_name} on #{related_models.map(&:name)}"
  related_models.each do |klass|
    klass.where(args_to_destroy).destroy_all
  end
end


30
31
32
33
34
35
# File 'lib/fme/enterprise_bus/jobs/cleanup_job.rb', line 30

def related_models
  Rails.application.eager_load!
  ApplicationRecord.descendants.select do |klass|
    klass.columns.map(&:name).include? column_name
  end
end