Sha256: 384de594c9768afef1ea5ba9b0ff2901ab8766d832d6c6437b5b0bc04bbf942e
Contents?: true
Size: 769 Bytes
Versions: 17
Compression:
Stored size: 769 Bytes
Contents
# frozen_string_literal: true module Cron # # Clean up the collection items that have not been updated in 30 days # class TrimCollection < Job cron_tab_entry :daily # # Fetch each item and delete it if hasn't been updated in 30 days # def perform # Rails.cache.reconnect count = 0 total = collection.count while count <= total collection.limit(250).skip(count).each { |item| item.destroy if archive?(item) } count += 250 end end # # Test if this should be archived # def archive?(item) item.updated_at < allowed_time end # # Allowed time the amount of time allowed to exists before deleting # def allowed_time 30.days.ago end end end
Version data entries
17 entries across 17 versions & 1 rubygems