mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 09:43:36 +02:00
113430903-new_job_added
This commit is contained in:
parent
28fcf0eb45
commit
57bd1c77b6
3 changed files with 20 additions and 12 deletions
16
app/jobs/domain_delete_job.rb
Normal file
16
app/jobs/domain_delete_job.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
class DomainDeleteJob < Que::Job
|
||||||
|
|
||||||
|
def run(domain_id)
|
||||||
|
domain = Domain.find(domain_id)
|
||||||
|
|
||||||
|
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
|
|
@ -4,5 +4,6 @@ class DomainSetDeleteCandidateJob < Que::Job
|
||||||
domain = Domain.find(domain_id)
|
domain = Domain.find(domain_id)
|
||||||
domain.statuses << DomainStatus::DELETE_CANDIDATE
|
domain.statuses << DomainStatus::DELETE_CANDIDATE
|
||||||
domain.save(validate: false)
|
domain.save(validate: false)
|
||||||
|
DomainDeleteJob.enqueue(domain.id, run_at: rand(24*60).minutes.from_now)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -87,22 +87,13 @@ class DomainCron
|
||||||
STDOUT << "#{Time.zone.now.utc} - Destroying domains\n" unless Rails.env.test?
|
STDOUT << "#{Time.zone.now.utc} - Destroying domains\n" unless Rails.env.test?
|
||||||
|
|
||||||
c = 0
|
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?
|
|
||||||
|
|
||||||
c += 1
|
|
||||||
end
|
|
||||||
|
|
||||||
Domain.where('force_delete_at <= ?', Time.zone.now).each do |x|
|
Domain.where('force_delete_at <= ?', Time.zone.now).each do |x|
|
||||||
WhoisRecord.where(domain_id: x.id).destroy_all
|
DomainDeleteJob.enqueue(x.id, run_at: rand(24*60).minutes.from_now)
|
||||||
destroy_with_message x
|
STDOUT << "#{Time.zone.now.utc} DomainCron.destroy_delete_candidates: job added by force delete time ##{x.id} (#{x.name})\n" unless Rails.env.test?
|
||||||
STDOUT << "#{Time.zone.now.utc} DomainCron.destroy_delete_candidates: by force delete time ##{x.id} (#{x.name})\n" unless Rails.env.test?
|
|
||||||
c += 1
|
c += 1
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# rubocop: enable Metrics/AbcSize
|
# rubocop: enable Metrics/AbcSize
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue