Class: Cron::TrimCollection
- Inherits:
-
Job
- Object
- ActiveJob::Base
- ApplicationJob
- Job
- Cron::TrimCollection
- Defined in:
- lib/app/jobs/cron/trim_collection.rb
Overview
Clean up the collection items that have not been updated in 30 days
Direct Known Subclasses
Instance Method Summary collapse
-
#allowed_time ⇒ Object
Allowed time the amount of time allowed to exists before deleting.
-
#archive?(item) ⇒ Boolean
Test if this should be archived.
-
#perform ⇒ Object
Fetch each item and delete it if hasn’t been updated in 30 days.
Methods inherited from Job
cron_tab_entry, #send_support_email
Methods inherited from ApplicationJob
valid_environment?, valid_environments
Methods included from App47Logger
#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
#allowed_time ⇒ Object
Allowed time the amount of time allowed to exists before deleting
32 33 34 |
# File 'lib/app/jobs/cron/trim_collection.rb', line 32 def allowed_time 30.days.ago end |
#archive?(item) ⇒ Boolean
Test if this should be archived
25 26 27 |
# File 'lib/app/jobs/cron/trim_collection.rb', line 25 def archive?(item) item.updated_at < allowed_time end |
#perform ⇒ Object
Fetch each item and delete it if hasn’t been updated in 30 days
12 13 14 15 16 17 18 19 20 |
# File 'lib/app/jobs/cron/trim_collection.rb', line 12 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 |