Class: Fme::EnterpriseBus::Jobs::CleanupJob
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- Fme::EnterpriseBus::Jobs::CleanupJob
- Defined in:
- lib/fme/enterprise_bus/jobs/cleanup_job.rb
Instance Method Summary collapse
- #args_to_destroy ⇒ Object
- #column_name ⇒ Object
- #organization_id ⇒ Object
- #perform(message) ⇒ Object
- #related_models ⇒ Object
Instance Method Details
#args_to_destroy ⇒ Object
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 => .assembly_id } if organization_id.present? built_arguments[:organization_id] = organization_id end built_arguments end |
#column_name ⇒ Object
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_id ⇒ Object
26 27 28 |
# File 'lib/fme/enterprise_bus/jobs/cleanup_job.rb', line 26 def organization_id .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() = Rails.logger.info "cleaning up #{column_name} on #{related_models.map(&:name)}" .each do |klass| klass.where(args_to_destroy).destroy_all end end |
#related_models ⇒ Object
30 31 32 33 34 35 |
# File 'lib/fme/enterprise_bus/jobs/cleanup_job.rb', line 30 def Rails.application.eager_load! ApplicationRecord.descendants.select do |klass| klass.columns.map(&:name).include? column_name end end |