forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Sets notifications that are older than a week to be purged by default. * Purging is run daily * Clears out notification recipients as well
- Loading branch information
1 parent
3190ed1
commit 3820086
Showing
6 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Notification | ||
module Purging | ||
extend ActiveSupport::Concern | ||
include PurgingMixin | ||
|
||
module ClassMethods | ||
def purge_date | ||
::Settings.notifications.history.keep_notifications.to_i_with_method.seconds.ago.utc | ||
end | ||
|
||
def purge_window_size | ||
::Settings.notifications.history.purge_window_size | ||
end | ||
|
||
def purge_scope(older_than) | ||
where(arel_table[:created_at].lt(older_than)) | ||
end | ||
|
||
def purge_associated_records(ids) | ||
NotificationRecipient.where(:notification_id => ids).delete_all | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
describe Notification do | ||
context "::Purging" do | ||
describe ".purge_by_date" do | ||
it "purges old notifications" do | ||
FactoryGirl.create(:user) | ||
FactoryGirl.create(:user) | ||
type = FactoryGirl.create(:notification_type, :audience => NotificationType::AUDIENCE_GLOBAL) | ||
|
||
# Notification and recipients that will not be purged | ||
new_notification = FactoryGirl.create(:notification, :notification_type => type) | ||
|
||
old_notification, semi_old_notification = nil | ||
Timecop.freeze(6.days.ago) do | ||
semi_old_notification = FactoryGirl.create(:notification, :notification_type => type) | ||
end | ||
|
||
Timecop.freeze(8.days.ago) do | ||
# Notification and recipients that will be purged | ||
old_notification = FactoryGirl.create(:notification, :notification_type => type) | ||
end | ||
|
||
expect(described_class.all).to match_array([new_notification, semi_old_notification, old_notification]) | ||
expect(NotificationRecipient.count).to eq(6) | ||
count = described_class.purge_by_date(described_class.purge_date) | ||
expect(described_class.all).to match_array([new_notification, semi_old_notification]) | ||
expect(NotificationRecipient.count).to eq(4) | ||
expect(count).to eq(1) | ||
end | ||
end | ||
|
||
describe ".purge_timer" do | ||
it "queues the correct purge method" do | ||
EvmSpecHelper.local_miq_server | ||
described_class.purge_timer | ||
q = MiqQueue.first | ||
expect(q).to have_attributes(:class_name => described_class.name, :method_name => "purge_by_date") | ||
end | ||
end | ||
end | ||
end |