Skip to content

Commit

Permalink
Merge pull request #737 from 3scale/delete_scheduled
Browse files Browse the repository at this point in the history
Enable for on-prem the deletion of accounts scheduled for deletion
  • Loading branch information
thomasmaas committed Apr 1, 2019
2 parents 5c1f243 + f7d9a94 commit fbca0b6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/workers/find_and_delete_scheduled_accounts_worker.rb
Expand Up @@ -4,6 +4,7 @@ class FindAndDeleteScheduledAccountsWorker
include Sidekiq::Worker

def perform
return unless ThreeScale.config.onpremises
Account.deleted_since.find_each(&DeleteAccountHierarchyWorker.method(:perform_later))
end
end
1 change: 1 addition & 0 deletions config/jobs.rb
Expand Up @@ -27,6 +27,7 @@ module Jobs
].freeze

DAILY = %w[
FindAndDeleteScheduledAccountsWorker.perform_async
Audited.audit_class.delete_old
LogEntry.delete_old
Cinstance.notify_about_expired_trial_periods
Expand Down
11 changes: 9 additions & 2 deletions test/workers/find_and_delete_accounts_scheduled_worker_test.rb
@@ -1,12 +1,19 @@
require 'test_helper'
class FindAndDeleteScheduledAccountsWorkerTest < ActiveSupport::TestCase
def test_perform
def setup
quiet_period_time = Account::States::PERIOD_BEFORE_DELETION
FactoryBot.create_list(:simple_buyer, 2)
FactoryBot.create_list(:simple_buyer, 3, state: 'scheduled_for_deletion', state_changed_at: quiet_period_time.ago)
FactoryBot.create_list(:simple_provider, 4, state: 'scheduled_for_deletion', state_changed_at: quiet_period_time.ago)
FactoryBot.create_list(:simple_provider, 1, state: 'scheduled_for_deletion', state_changed_at: quiet_period_time.ago + 1.day)
assert_equal 7, Account.deleted_since.count
end

def test_perform
ThreeScale.config.stubs(onpremises: false)
DeleteAccountHierarchyWorker.expects(:perform_later).never
FindAndDeleteScheduledAccountsWorker.new.perform

ThreeScale.config.stubs(onpremises: true)
DeleteAccountHierarchyWorker.expects(:perform_later).times(7)
FindAndDeleteScheduledAccountsWorker.new.perform
end
Expand Down

0 comments on commit fbca0b6

Please sign in to comment.