-
-
Notifications
You must be signed in to change notification settings - Fork 472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
draft case contact cleanup #5918
base: main
Are you sure you want to change the base?
Changes from 1 commit
9de7d46
b182557
6b6d353
ac66d5d
d34fae5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class DraftCaseContactCleanupService | ||
def self.call | ||
draft_expiration = 1.week.ago | ||
draft_expiration_without_case = 1.day.ago | ||
drafts_for_removal = CaseContact.where.not(status: "active").where("case_contacts.created_at < ?", draft_expiration) | ||
.or(CaseContact.where.not(status: "active").where(draft_case_ids: []).where("case_contacts.created_at < ?", draft_expiration_without_case)) | ||
|
||
drafts_for_removal.each do |draft| | ||
draft.destroy | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
desc "delete draft case contacts marked for clean up, run by heroku scheduler." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good desc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for later PR thought - we may want to move away from heroku scheduler towards something like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not that familiar with heroku scheduler but would like to learn so I'm curious, what's the rationale for moving away from it in favor of Sidekiq? |
||
task case_contact_draft_cleanup: :environment do | ||
CaseContact.drafts_for_removal.each do |draft| | ||
draft.destroy | ||
end | ||
DraftCaseContactCleanupService.call | ||
end |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good test 👍 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe DraftCaseContactCleanupService do | ||
describe ".call" do | ||
let!(:past_expiration) { Time.now - 8.days } | ||
let!(:past_exp_without_case) { Time.now - 2.days } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also do |
||
let!(:active_case_contact) { create(:case_contact, status: "active") } | ||
let!(:new_draft_case_contact) { create(:case_contact, status: "started", created_at: Time.now, draft_case_ids: []) } | ||
let!(:draft_case_contact_without_draft_case_id) { create(:case_contact, status: "started", created_at: past_exp_without_case, draft_case_ids: []) } | ||
let!(:draft_case_contact_with_draft_case_id) { create(:case_contact, status: "started", created_at: past_exp_without_case, draft_case_ids: [1]) } | ||
let!(:eight_day_draft_case_contact) { create(:case_contact, status: "details", created_at: past_expiration) } | ||
let!(:eight_day_active_case_contact) { create(:case_contact, status: "active", created_at: past_expiration) } | ||
|
||
it "returns drafts not attached to cases and drafts older than a week" do | ||
expect { described_class.call }.to change { CaseContact.count }.by(-2) | ||
|
||
expect(CaseContact.where(id: draft_case_contact_without_draft_case_id.id)).to be_empty | ||
expect(CaseContact.where(id: eight_day_draft_case_contact.id)).to be_empty | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant constants like
DRAFT_EXPIRATION_DELAY
andORPHANED_DRAFT_EXPIRATION_DELAY
Not sure if orphaned is a better name