Sha256: e4ab2c6ed5eafe37effd3884825bf5eb99655313977c54506d0860e83d30dc2d

Contents?: true

Size: 1.25 KB

Versions: 56

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Cron
  #
  # Trim notifications in system after 30 days.
  #
  # This was historically done by a database index, however with the introduction
  # of adding an email attachment, and thus another collection, this needed to move
  # to a daily job here so that:
  # 1. the object hierarchy is deleted
  # 2. The paperclip call backs are fired to remove the file from S3
  #
  # In case you are wondering why not make it an embedded class and allow the index
  # method to still work, the answer is that it won't clean up the S3 files.
  #
  class TrimNotifications < TrimCollection
    #
    # Return the collection
    #
    def collection
      Notification.all
    end

    #
    # Test if this should be archived
    #
    def archive?(item)
      time = if item.is_a?(EmailNotification) && template?(item)
               5.years.ago.utc
             else
               allowed_time_for_item(item)
             end
      item.updated_at < time
    end

    #
    # Determine if the notification has a template associated with it
    #
    def template?(item)
      item.notification_template.present? ||
        item[:notification_template_id].present? && Template.where(_id: item[:notification_template_id]).present?
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
web47core-3.2.20 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.19 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.18 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.17 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.16 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.15 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.14 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.13 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.12 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.9 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.8 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.7 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.6 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.5 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.4 lib/app/jobs/cron/trim_notifications.rb
web47core-2.2.20 lib/app/jobs/cron/trim_notifications.rb
web47core-2.2.19 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.3 lib/app/jobs/cron/trim_notifications.rb
web47core-3.2.2 lib/app/jobs/cron/trim_notifications.rb
web47core-2.2.15 lib/app/jobs/cron/trim_notifications.rb