1 require 'current_api_client'
3 module SweepTrashedCollections
4 extend CurrentApiClient
9 where('delete_at is not null and delete_at < statement_timestamp()').
12 where('is_trashed = false and trash_at < statement_timestamp()').
13 update_all('is_trashed = true')
17 def self.sweep_if_stale
18 return if Rails.configuration.trash_sweep_interval <= 0
19 exp = Rails.configuration.trash_sweep_interval.seconds
21 Rails.cache.fetch('SweepTrashedCollections', expires_in: exp) do
26 Thread.current.abort_on_exception = false
30 Rails.logger.error "#{e.class}: #{e}\n#{e.backtrace.join("\n\t")}"
32 ActiveRecord::Base.connection.close