mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 10:49:39 +02:00
parent
0cc3a53deb
commit
f127716a39
5 changed files with 36 additions and 22 deletions
|
@ -1,11 +1,9 @@
|
||||||
class DomainExpirationEmailJob < ActiveJob::Base
|
class DomainExpirationEmailJob < Que::Job
|
||||||
queue_as :default
|
def run(domain_id:)
|
||||||
|
|
||||||
def perform(domain_id:)
|
|
||||||
domain = Domain.find(domain_id)
|
domain = Domain.find(domain_id)
|
||||||
|
|
||||||
return if domain.registered?
|
return if domain.registered?
|
||||||
|
|
||||||
DomainMailer.expiration(domain).deliver!
|
DomainMailer.expiration(domain: domain).deliver!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,18 +32,27 @@ class DomainCron
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.start_expire_period
|
def self.start_expire_period
|
||||||
STDOUT << "#{Time.zone.now.utc} - Expiring domains\n" unless Rails.env.test?
|
Rails.logger.info('Expiring domains')
|
||||||
|
|
||||||
::PaperTrail.whodunnit = "cron - #{__method__}"
|
::PaperTrail.whodunnit = "cron - #{__method__}"
|
||||||
domains = Domain.where('valid_to <= ?', Time.zone.now)
|
|
||||||
|
domains = Domain.expired
|
||||||
marked = 0
|
marked = 0
|
||||||
real = 0
|
real = 0
|
||||||
|
|
||||||
domains.each do |domain|
|
domains.each do |domain|
|
||||||
next unless domain.expirable?
|
next unless domain.expirable?
|
||||||
real += 1
|
real += 1
|
||||||
domain.set_graceful_expired
|
domain.set_graceful_expired
|
||||||
STDOUT << "#{Time.zone.now.utc} DomainCron.start_expire_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test?
|
STDOUT << "#{Time.zone.now.utc} DomainCron.start_expire_period: ##{domain.id} (#{domain.name}) #{domain.changes}\n" unless Rails.env.test?
|
||||||
domain.save(validate: false) and marked += 1
|
|
||||||
|
send_time = domain.valid_to + Setting.expiration_reminder_mail.to_i.days
|
||||||
|
saved = domain.save(validate: false)
|
||||||
|
|
||||||
|
if saved
|
||||||
|
DomainExpirationEmailJob.enqueue(domain_id: domain.id, run_at: send_time)
|
||||||
|
marked += 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
STDOUT << "#{Time.zone.now.utc} - Successfully expired #{marked} of #{real} domains\n" unless Rails.env.test?
|
STDOUT << "#{Time.zone.now.utc} - Successfully expired #{marked} of #{real} domains\n" unless Rails.env.test?
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe DomainExpirationEmailJob do
|
RSpec.describe DomainExpirationEmailJob do
|
||||||
it 'queues the job' do
|
describe '#run' do
|
||||||
expect { described_class.perform_later }.to have_enqueued_job(described_class)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#perform' do
|
|
||||||
let(:domain) { instance_double(Domain) }
|
let(:domain) { instance_double(Domain) }
|
||||||
|
|
||||||
before :example do
|
before :example do
|
||||||
|
@ -22,7 +18,7 @@ RSpec.describe DomainExpirationEmailJob do
|
||||||
it 'sends email notification' do
|
it 'sends email notification' do
|
||||||
expect(DomainMailer).to receive(:expiration).with(domain: domain).and_return(message)
|
expect(DomainMailer).to receive(:expiration).with(domain: domain).and_return(message)
|
||||||
expect(message).to receive(:deliver!)
|
expect(message).to receive(:deliver!)
|
||||||
described_class.perform_now(domain_id: 1)
|
described_class.enqueue(domain_id: 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -33,7 +29,7 @@ RSpec.describe DomainExpirationEmailJob do
|
||||||
|
|
||||||
it 'does not send email notification' do
|
it 'does not send email notification' do
|
||||||
expect(DomainMailer).to_not receive(:expiration)
|
expect(DomainMailer).to_not receive(:expiration)
|
||||||
described_class.perform_now(domain_id: 1)
|
described_class.enqueue(domain_id: 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe DomainCron do
|
RSpec.describe DomainCron do
|
||||||
before :example do
|
|
||||||
Fabricate(:zonefile_setting, origin: 'ee')
|
|
||||||
|
|
||||||
@domain = Fabricate(:domain)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should expire domains' do
|
it 'should expire domains' do
|
||||||
|
Fabricate(:zonefile_setting, origin: 'ee')
|
||||||
|
@domain = Fabricate(:domain)
|
||||||
|
|
||||||
Setting.expire_warning_period = 1
|
Setting.expire_warning_period = 1
|
||||||
Setting.redemption_grace_period = 1
|
Setting.redemption_grace_period = 1
|
||||||
|
|
||||||
|
@ -28,6 +25,9 @@ RSpec.describe DomainCron do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should start redemption grace period' do
|
it 'should start redemption grace period' do
|
||||||
|
Fabricate(:zonefile_setting, origin: 'ee')
|
||||||
|
@domain = Fabricate(:domain)
|
||||||
|
|
||||||
old_valid_to = Time.zone.now - 10.days
|
old_valid_to = Time.zone.now - 10.days
|
||||||
@domain.valid_to = old_valid_to
|
@domain.valid_to = old_valid_to
|
||||||
@domain.statuses = [DomainStatus::EXPIRED]
|
@domain.statuses = [DomainStatus::EXPIRED]
|
||||||
|
@ -38,4 +38,15 @@ RSpec.describe DomainCron do
|
||||||
@domain.reload
|
@domain.reload
|
||||||
@domain.statuses.include?(DomainStatus::EXPIRED).should == true
|
@domain.statuses.include?(DomainStatus::EXPIRED).should == true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '::start_expire_period', db: false do
|
||||||
|
before :example do
|
||||||
|
travel_to Time.zone.parse('05.07.2010')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'logs start time' do
|
||||||
|
expect(Rails.logger).to receive(:info).with('Expiring domains')
|
||||||
|
described_class.start_expire_period
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe RegistrarPresenter do
|
RSpec.describe RegistrarPresenter do
|
||||||
let(:registrar) { instance_double(Registrar) }
|
let(:registrar) { instance_double(Registrar) }
|
||||||
let(:presenter) { described_class.new(registrar: registrar, view: nil) }
|
let(:presenter) { described_class.new(registrar: registrar, view: view) }
|
||||||
|
|
||||||
describe '#name' do
|
describe '#name' do
|
||||||
it 'returns name' do
|
it 'returns name' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue