mirror of
https://github.com/internetee/registry.git
synced 2025-07-19 17:25:57 +02:00
Improve domain's outzone and delete logic
- Encapsulate outzone and delete candidate logic into domain model - Fix the logic itself Fixes #238
This commit is contained in:
parent
e653d8b56e
commit
aa29c781f6
3 changed files with 58 additions and 8 deletions
|
@ -53,10 +53,12 @@ class DomainCron
|
|||
STDOUT << "#{Time.zone.now.utc} - Setting server_hold to domains\n" unless Rails.env.test?
|
||||
|
||||
::PaperTrail.whodunnit = "cron - #{__method__}"
|
||||
d = Domain.where('outzone_at <= ?', Time.zone.now)
|
||||
|
||||
domains = Domain.outzone_candidates
|
||||
marked = 0
|
||||
real = 0
|
||||
d.each do |domain|
|
||||
|
||||
domains.each do |domain|
|
||||
next unless domain.server_holdable?
|
||||
real += 1
|
||||
domain.statuses << DomainStatus::SERVER_HOLD
|
||||
|
@ -96,16 +98,18 @@ class DomainCron
|
|||
|
||||
c = 0
|
||||
|
||||
Domain.where('delete_at <= ?', Time.zone.now.end_of_day.utc).each do |x|
|
||||
next unless x.delete_candidateable?
|
||||
domains = Domain.delete_candidates
|
||||
|
||||
x.statuses << DomainStatus::DELETE_CANDIDATE
|
||||
domains.each do |domain|
|
||||
next unless domain.delete_candidateable?
|
||||
|
||||
domain.statuses << DomainStatus::DELETE_CANDIDATE
|
||||
|
||||
# If domain successfully saved, add it to delete schedule
|
||||
if x.save(validate: false)
|
||||
if domain.save(validate: false)
|
||||
::PaperTrail.whodunnit = "cron - #{__method__}"
|
||||
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?
|
||||
DomainDeleteJob.enqueue(domain.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 ##{domain.id} (#{domain.name})\n" unless Rails.env.test?
|
||||
c += 1
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue