Class: Cron::TrimNotifications
- Inherits:
-
TrimCollection
- Object
- ActiveJob::Base
- ApplicationJob
- Job
- TrimCollection
- Cron::TrimNotifications
- Defined in:
- lib/app/jobs/cron/trim_notifications.rb
Overview
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:
-
the object hierarchy is deleted
-
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.
Instance Attribute Summary
Attributes inherited from ApplicationJob
Instance Method Summary collapse
-
#archive?(item) ⇒ Boolean
Test if this should be archived.
-
#collection ⇒ Object
Return the collection.
-
#template?(item) ⇒ Boolean
Determine if the notification has a template associated with it.
Methods inherited from TrimCollection
#allowed_time, #allowed_time_for_item, #comparison_field, #execute, #trim_item
Methods inherited from Job
cron_tab_entry, #notify_job_failure, #send_support_email
Methods inherited from ApplicationJob
#duration, #parse_payload, #perform, valid_environment?, valid_environments
Methods included from App47Logger
clean_params, #clean_params, delete_parameter_keys, #log_controller_error, log_debug, #log_debug, log_error, #log_error, log_exception, #log_message, log_message, #log_warn, log_warn, mask_parameter_keys, #update_flash_messages
Instance Method Details
#archive?(item) ⇒ Boolean
Test if this should be archived
27 28 29 30 31 32 33 34 |
# File 'lib/app/jobs/cron/trim_notifications.rb', line 27 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 |
#collection ⇒ Object
Return the collection
20 21 22 |
# File 'lib/app/jobs/cron/trim_notifications.rb', line 20 def collection Notification.all end |
#template?(item) ⇒ Boolean
Determine if the notification has a template associated with it
39 40 41 42 |
# File 'lib/app/jobs/cron/trim_notifications.rb', line 39 def template?(item) item.notification_template.present? || item[:notification_template_id].present? && Template.where(_id: item[:notification_template_id]).present? end |