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

Version Path
web47core-0.3.4 lib/app/jobs/cron/trim_collection.rb
web47core-0.3.3 lib/app/jobs/cron/trim_collection.rb
web47core-0.3.2 lib/app/jobs/cron/trim_collection.rb
web47core-0.3.1 lib/app/jobs/cron/trim_collection.rb
web47core-0.3.0 lib/app/jobs/cron/trim_collection.rb
web47core-0.1.11 lib/app/jobs/cron/trim_collection.rb
web47core-0.1.10 lib/app/jobs/cron/trim_collection.rb
web47core-0.1.9 lib/app/jobs/cron/trim_collection.rb
web47core-0.1.8 lib/app/jobs/cron/trim_collection.rb
web47core-0.1.7 lib/app/jobs/cron/trim_collection.rb
web47core-0.1.6 lib/app/jobs/cron/trim_collection.rb
web47core-0.1.5 lib/app/jobs/cron/trim_collection.rb
web47core-0.1.4 lib/app/jobs/cron/trim_collection.rb
web47core-0.1.3 lib/app/jobs/cron/trim_collection.rb
web47core-0.1.2 lib/app/jobs/cron/trim_collection.rb
web47core-0.1.1 lib/app/jobs/cron/trim_collection.rb
web47core-0.1.0 lib/app/jobs/cron/trim_collection.rb