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.
Add purge timer for archived entities
- Loading branch information
Ari Zellner
committed
Apr 12, 2017
1 parent
9cae782
commit 88dd01c
Showing
19 changed files
with
363 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Container < ApplicationRecord | ||
module Purging | ||
extend ActiveSupport::Concern | ||
include PurgingMixin | ||
|
||
module ClassMethods | ||
def purge_date | ||
::Settings.container_entities.history.keep_archived_entities.to_i_with_method.seconds.ago.utc | ||
end | ||
|
||
def purge_window_size | ||
::Settings.container_entities.history.purge_window_size | ||
end | ||
|
||
def purge_scope(older_than) | ||
where(arel_table[:deleted_on].lteq(older_than)) | ||
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,20 @@ | ||
class ContainerDefinition < ApplicationRecord | ||
module Purging | ||
extend ActiveSupport::Concern | ||
include PurgingMixin | ||
|
||
module ClassMethods | ||
def purge_date | ||
::Settings.container_entities.history.keep_archived_entities.to_i_with_method.seconds.ago.utc | ||
end | ||
|
||
def purge_window_size | ||
::Settings.container_entities.history.purge_window_size | ||
end | ||
|
||
def purge_scope(older_than) | ||
where(arel_table[:deleted_on].lteq(older_than)) | ||
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,20 @@ | ||
class ContainerGroup < ApplicationRecord | ||
module Purging | ||
extend ActiveSupport::Concern | ||
include PurgingMixin | ||
|
||
module ClassMethods | ||
def purge_date | ||
::Settings.container_entities.history.keep_archived_entities.to_i_with_method.seconds.ago.utc | ||
end | ||
|
||
def purge_window_size | ||
::Settings.container_entities.history.purge_window_size | ||
end | ||
|
||
def purge_scope(older_than) | ||
where(arel_table[:deleted_on].lteq(older_than)) | ||
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,20 @@ | ||
class ContainerImage < ApplicationRecord | ||
module Purging | ||
extend ActiveSupport::Concern | ||
include PurgingMixin | ||
|
||
module ClassMethods | ||
def purge_date | ||
::Settings.container_entities.history.keep_archived_entities.to_i_with_method.seconds.ago.utc | ||
end | ||
|
||
def purge_window_size | ||
::Settings.container_entities.history.purge_window_size | ||
end | ||
|
||
def purge_scope(older_than) | ||
where(arel_table[:deleted_on].lteq(older_than)) | ||
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,20 @@ | ||
class ContainerProject < ApplicationRecord | ||
module Purging | ||
extend ActiveSupport::Concern | ||
include PurgingMixin | ||
|
||
module ClassMethods | ||
def purge_date | ||
::Settings.container_entities.history.keep_archived_entities.to_i_with_method.seconds.ago.utc | ||
end | ||
|
||
def purge_window_size | ||
::Settings.container_entities.history.purge_window_size | ||
end | ||
|
||
def purge_scope(older_than) | ||
where(arel_table[:deleted_on].lteq(older_than)) | ||
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
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,4 @@ | ||
FactoryGirl.define do | ||
factory :container_definition do | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
describe Container do | ||
context "::Purging" do | ||
context ".purge_queue" do | ||
before do | ||
EvmSpecHelper.create_guid_miq_server_zone | ||
end | ||
let(:purge_time) { (Time.zone.now + 10).round } | ||
|
||
it "submits to the queue" do | ||
expect(described_class).to receive(:purge_date).and_return(purge_time) | ||
described_class.purge_timer | ||
|
||
q = MiqQueue.all | ||
expect(q.length).to eq(1) | ||
expect(q.first).to have_attributes( | ||
:class_name => described_class.name, | ||
:method_name => "purge_by_date", | ||
:args => [purge_time] | ||
) | ||
end | ||
end | ||
|
||
context ".purge" do | ||
let(:deleted_date) { 6.months.ago } | ||
|
||
before do | ||
@old_container = FactoryGirl.create(:container, :deleted_on => deleted_date - 1.day) | ||
@purge_date_container = FactoryGirl.create(:container, :deleted_on => deleted_date) | ||
@new_container = FactoryGirl.create(:container, :deleted_on => deleted_date + 1.day) | ||
end | ||
|
||
def assert_unpurged_ids(unpurged_ids) | ||
expect(described_class.order(:id).pluck(:id)).to eq(Array(unpurged_ids).sort) | ||
end | ||
|
||
it "purge_date and older" do | ||
described_class.purge(deleted_date) | ||
assert_unpurged_ids(@new_container.id) | ||
end | ||
|
||
it "with a window" do | ||
described_class.purge(deleted_date, 1) | ||
assert_unpurged_ids(@new_container.id) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
describe ContainerDefinition do | ||
context "::Purging" do | ||
context ".purge_queue" do | ||
before do | ||
EvmSpecHelper.create_guid_miq_server_zone | ||
end | ||
let(:purge_time) { (Time.zone.now + 10).round } | ||
|
||
it "submits to the queue" do | ||
expect(described_class).to receive(:purge_date).and_return(purge_time) | ||
described_class.purge_timer | ||
|
||
q = MiqQueue.all | ||
expect(q.length).to eq(1) | ||
expect(q.first).to have_attributes( | ||
:class_name => described_class.name, | ||
:method_name => "purge_by_date", | ||
:args => [purge_time] | ||
) | ||
end | ||
end | ||
|
||
context ".purge" do | ||
let(:deleted_date) { 6.months.ago } | ||
|
||
before do | ||
@old_container_def = FactoryGirl.create(:container_definition, :deleted_on => deleted_date - 1.day) | ||
@purge_date_container_def = FactoryGirl.create(:container_definition, :deleted_on => deleted_date) | ||
@new_container_def = FactoryGirl.create(:container_definition, :deleted_on => deleted_date + 1.day) | ||
end | ||
|
||
def assert_unpurged_ids(unpurged_ids) | ||
expect(described_class.order(:id).pluck(:id)).to eq(Array(unpurged_ids).sort) | ||
end | ||
|
||
it "purge_date and older" do | ||
described_class.purge(deleted_date) | ||
assert_unpurged_ids(@new_container_def.id) | ||
end | ||
|
||
it "with a window" do | ||
described_class.purge(deleted_date, 1) | ||
assert_unpurged_ids(@new_container_def.id) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
describe ContainerGroup do | ||
context "::Purging" do | ||
context ".purge_queue" do | ||
before do | ||
EvmSpecHelper.create_guid_miq_server_zone | ||
end | ||
let(:purge_time) { (Time.zone.now + 10).round } | ||
|
||
it "submits to the queue" do | ||
expect(described_class).to receive(:purge_date).and_return(purge_time) | ||
described_class.purge_timer | ||
|
||
q = MiqQueue.all | ||
expect(q.length).to eq(1) | ||
expect(q.first).to have_attributes( | ||
:class_name => described_class.name, | ||
:method_name => "purge_by_date", | ||
:args => [purge_time] | ||
) | ||
end | ||
end | ||
|
||
context ".purge" do | ||
let(:deleted_date) { 6.months.ago } | ||
|
||
before do | ||
@old_container_group = FactoryGirl.create(:container_group, :deleted_on => deleted_date - 1.day) | ||
@purge_date_container_group = FactoryGirl.create(:container_group, :deleted_on => deleted_date) | ||
@new_container_group = FactoryGirl.create(:container_group, :deleted_on => deleted_date + 1.day) | ||
end | ||
|
||
def assert_unpurged_ids(unpurged_ids) | ||
expect(described_class.order(:id).pluck(:id)).to eq(Array(unpurged_ids).sort) | ||
end | ||
|
||
it "purge_date and older" do | ||
described_class.purge(deleted_date) | ||
assert_unpurged_ids(@new_container_group.id) | ||
end | ||
|
||
it "with a window" do | ||
described_class.purge(deleted_date, 1) | ||
assert_unpurged_ids(@new_container_group.id) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
describe ContainerImage do | ||
context "::Purging" do | ||
context ".purge_queue" do | ||
before do | ||
EvmSpecHelper.create_guid_miq_server_zone | ||
end | ||
let(:purge_time) { (Time.zone.now + 10).round } | ||
|
||
it "submits to the queue" do | ||
expect(described_class).to receive(:purge_date).and_return(purge_time) | ||
described_class.purge_timer | ||
|
||
q = MiqQueue.all | ||
expect(q.length).to eq(1) | ||
expect(q.first).to have_attributes( | ||
:class_name => described_class.name, | ||
:method_name => "purge_by_date", | ||
:args => [purge_time] | ||
) | ||
end | ||
end | ||
|
||
context ".purge" do | ||
let(:deleted_date) { 6.months.ago } | ||
|
||
before do | ||
@old_container_image = FactoryGirl.create(:container_image, :deleted_on => deleted_date - 1.day) | ||
@purge_date_container_image = FactoryGirl.create(:container_image, :deleted_on => deleted_date) | ||
@new_container_image = FactoryGirl.create(:container_image, :deleted_on => deleted_date + 1.day) | ||
end | ||
|
||
def assert_unpurged_ids(unpurged_ids) | ||
expect(described_class.order(:id).pluck(:id)).to eq(Array(unpurged_ids).sort) | ||
end | ||
|
||
it "purge_date and older" do | ||
described_class.purge(deleted_date) | ||
assert_unpurged_ids(@new_container_image.id) | ||
end | ||
|
||
it "with a window" do | ||
described_class.purge(deleted_date, 1) | ||
assert_unpurged_ids(@new_container_image.id) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.