feat(captain-memory): add HardDeleteExpiredJob with daily cron (LGPD)
This commit is contained in:
parent
b3077b2b26
commit
2261b09b25
@ -113,3 +113,9 @@ captain_contact_memory_aging_job:
|
||||
cron: '0 3 * * 0'
|
||||
class: 'Captain::ContactMemories::AgingJob'
|
||||
queue: scheduled_jobs
|
||||
|
||||
# daily at 03:30 UTC - hard-delete soft-deleted contact memories older than 30 days (LGPD)
|
||||
captain_contact_memory_hard_delete_job:
|
||||
cron: '30 3 * * *'
|
||||
class: 'Captain::ContactMemories::HardDeleteExpiredJob'
|
||||
queue: scheduled_jobs
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
class Captain::ContactMemories::HardDeleteExpiredJob < ApplicationJob
|
||||
queue_as :scheduled_jobs
|
||||
|
||||
RETENTION_DAYS = 30
|
||||
|
||||
def perform
|
||||
count = Captain::ContactMemory.where('deleted_at < ?', RETENTION_DAYS.days.ago).delete_all
|
||||
Rails.logger.info("[ContactMemory::HardDeleteExpiredJob] hard-deleted #{count} records")
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,15 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Captain::ContactMemories::HardDeleteExpiredJob do
|
||||
it 'destroys records soft-deleted more than 30 days ago' do
|
||||
old = create(:captain_contact_memory, deleted_at: 40.days.ago)
|
||||
recent = create(:captain_contact_memory, deleted_at: 10.days.ago)
|
||||
active = create(:captain_contact_memory, deleted_at: nil)
|
||||
|
||||
described_class.perform_now
|
||||
|
||||
expect(Captain::ContactMemory.exists?(old.id)).to be(false)
|
||||
expect(Captain::ContactMemory.exists?(recent.id)).to be(true)
|
||||
expect(Captain::ContactMemory.exists?(active.id)).to be(true)
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user