Class: Joblin::BackgroundTask::RetentionPolicy::BackgroundTaskCleaner
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- Joblin::BackgroundTask::RetentionPolicy::BackgroundTaskCleaner
- Defined in:
- app/models/joblin/background_task/retention_policy.rb
Instance Method Summary collapse
Instance Method Details
#perform ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/joblin/background_task/retention_policy.rb', line 17 def perform types = BackgroundTask.distinct.pluck(:type) types.each do |type_name| klass = type_name ? type_name.safe_constantize : BackgroundTask # Skip rows whose class has been renamed/removed rather than aborting # the whole cleanup run. next unless klass && klass <= BackgroundTask rp = klass.record_retention next unless rp # Scope by the exact type column so a parent policy doesn't reap # subclass rows that declared their own (longer) retention. BackgroundTask.where(type: type_name) .where("created_at < ?", rp.ago) .destroy_all end end |