mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 02:39:37 +02:00
Merge pull request #112 from internetee/113430903-delete_candidate_randomizer
113430903 delete candidate randomizer
This commit is contained in:
commit
eca211a014
3 changed files with 36 additions and 11 deletions
17
app/jobs/domain_delete_job.rb
Normal file
17
app/jobs/domain_delete_job.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class DomainDeleteJob < Que::Job
|
||||
|
||||
def run(domain_id)
|
||||
domain = Domain.find(domain_id)
|
||||
|
||||
::PaperTrail.whodunnit = "job - #{self.class.name}"
|
||||
WhoisRecord.where(domain_id: domain.id).destroy_all
|
||||
|
||||
domain.destroy
|
||||
bye_bye = domain.versions.last
|
||||
domain.registrar.messages.create!(
|
||||
body: "#{I18n.t(:domain_deleted)}: #{domain.name}",
|
||||
attached_obj_id: bye_bye.id,
|
||||
attached_obj_type: bye_bye.class.to_s
|
||||
)
|
||||
end
|
||||
end
|
10
app/jobs/domain_set_delete_candidate_job.rb
Normal file
10
app/jobs/domain_set_delete_candidate_job.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class DomainSetDeleteCandidateJob < Que::Job
|
||||
|
||||
def run(domain_id)
|
||||
domain = Domain.find(domain_id)
|
||||
domain.statuses << DomainStatus::DELETE_CANDIDATE
|
||||
::PaperTrail.whodunnit = "job - #{self.class.name}"
|
||||
domain.save(validate: false)
|
||||
DomainDeleteJob.enqueue(domain.id, run_at: rand(((24*60) - (DateTime.now.hour * 60 + DateTime.now.minute))).minutes.from_now)
|
||||
end
|
||||
end
|
|
@ -75,12 +75,11 @@ class DomainCron
|
|||
d.each do |domain|
|
||||
next unless domain.delete_candidateable?
|
||||
real += 1
|
||||
domain.statuses << DomainStatus::DELETE_CANDIDATE
|
||||
STDOUT << "#{Time.zone.now.utc} DomainCron.start_delete_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test?
|
||||
domain.save(validate: false) and marked += 1
|
||||
STDOUT << "#{Time.zone.now.utc} DomainCron.start_delete_period: ##{domain.id} (#{domain.name})\n" unless Rails.env.test?
|
||||
DomainSetDeleteCandidateJob.enqueue(domain.id, run_at: rand(((24*60) - (DateTime.now.hour * 60 + DateTime.now.minute))).minutes.from_now) and marked += 1
|
||||
end
|
||||
ensure # the operator should see what was accomplished
|
||||
STDOUT << "#{Time.zone.now.utc} - Finished setting delete_candidate - #{marked} out of #{real} successfully set\n" unless Rails.env.test?
|
||||
STDOUT << "#{Time.zone.now.utc} - Finished setting schedule for delete_candidate - #{marked} out of #{real} successfully added to Que schedule\n" unless Rails.env.test?
|
||||
end
|
||||
marked
|
||||
end
|
||||
|
@ -89,22 +88,21 @@ class DomainCron
|
|||
STDOUT << "#{Time.zone.now.utc} - Destroying domains\n" unless Rails.env.test?
|
||||
|
||||
c = 0
|
||||
|
||||
Domain.where("statuses @> '{deleteCandidate}'::varchar[]").each do |x|
|
||||
WhoisRecord.where(domain_id: x.id).destroy_all
|
||||
destroy_with_message x
|
||||
STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: by deleteCandidate ##{x.id} (#{x.name})\n" unless Rails.env.test?
|
||||
|
||||
DomainDeleteJob.enqueue(x.id, run_at: rand(((24*60) - (DateTime.now.hour * 60 + DateTime.now.minute))).minutes.from_now)
|
||||
STDOUT << "#{Time.zone.now.utc} Domain.destroy_delete_candidates: job added by deleteCandidate status ##{x.id} (#{x.name})\n" unless Rails.env.test?
|
||||
c += 1
|
||||
end
|
||||
|
||||
Domain.where('force_delete_at <= ?', Time.zone.now).each do |x|
|
||||
WhoisRecord.where(domain_id: x.id).destroy_all
|
||||
destroy_with_message x
|
||||
STDOUT << "#{Time.zone.now.utc} DomainCron.destroy_delete_candidates: by force delete time ##{x.id} (#{x.name})\n" unless Rails.env.test?
|
||||
DomainDeleteJob.enqueue(x.id, run_at: rand(((24*60) - (DateTime.now.hour * 60 + DateTime.now.minute))).minutes.from_now)
|
||||
STDOUT << "#{Time.zone.now.utc} DomainCron.destroy_delete_candidates: job added by force delete time ##{x.id} (#{x.name})\n" unless Rails.env.test?
|
||||
c += 1
|
||||
end
|
||||
|
||||
STDOUT << "#{Time.zone.now.utc} - Successfully destroyed #{c} domains\n" unless Rails.env.test?
|
||||
STDOUT << "#{Time.zone.now.utc} - Job destroy added for #{c} domains\n" unless Rails.env.test?
|
||||
end
|
||||
|
||||
# rubocop: enable Metrics/AbcSize
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue