Sha256: 3bad2cc333eef60783bd55cee0fc50bbd031ab7cd96f75000a313df39c1b2fca

Contents?: true

Size: 1.23 KB

Versions: 31

Compression:

Stored size: 1.23 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
             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

31 entries across 31 versions & 1 rubygems

Version Path
web47core-1.0.14 lib/app/jobs/cron/trim_notifications.rb
web47core-1.0.13 lib/app/jobs/cron/trim_notifications.rb
web47core-1.0.12 lib/app/jobs/cron/trim_notifications.rb
web47core-1.0.11 lib/app/jobs/cron/trim_notifications.rb
web47core-1.0.10 lib/app/jobs/cron/trim_notifications.rb
web47core-1.0.8 lib/app/jobs/cron/trim_notifications.rb
web47core-1.0.7 lib/app/jobs/cron/trim_notifications.rb
web47core-1.0.6 lib/app/jobs/cron/trim_notifications.rb
web47core-1.0.5 lib/app/jobs/cron/trim_notifications.rb
web47core-1.0.4 lib/app/jobs/cron/trim_notifications.rb
web47core-1.0.3 lib/app/jobs/cron/trim_notifications.rb
web47core-1.0.2 lib/app/jobs/cron/trim_notifications.rb
web47core-1.0.1 lib/app/jobs/cron/trim_notifications.rb
web47core-1.0.0 lib/app/jobs/cron/trim_notifications.rb
web47core-0.9.9 lib/app/jobs/cron/trim_notifications.rb
web47core-0.9.8 lib/app/jobs/cron/trim_notifications.rb
web47core-0.9.7 lib/app/jobs/cron/trim_notifications.rb
web47core-0.9.6 lib/app/jobs/cron/trim_notifications.rb
web47core-0.9.0 lib/app/jobs/cron/trim_notifications.rb
web47core-0.8.5 lib/app/jobs/cron/trim_notifications.rb