Skip to content

Commit

Permalink
Make sidekiq jobs discardable
Browse files Browse the repository at this point in the history
  • Loading branch information
yulgolem committed Mar 12, 2021
1 parent b77b78c commit b24023c
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
3 changes: 2 additions & 1 deletion app/jobs/registrant_change_expired_email_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ def perform(domain_id)
private

def log(domain)
message = "Send RegistrantChangeMailer#expired email for domain #{domain.name} (##{domain.id}) to #{domain.new_registrant_email}"
message = 'Send RegistrantChangeMailer#expired email for domain '\
"#{domain.name} (##{domain.id}) to #{domain.new_registrant_email}"
logger.info(message)
end

Expand Down
8 changes: 6 additions & 2 deletions app/models/concerns/domain/deletable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ def delete_later
end

def do_not_delete_later
# Que job can be manually deleted in admin area UI
QueJob.find_by("args->>0 = '#{id}'", job_class: DomainDeleteJob.name)&.destroy
return if Rails.env.test?

jobs = Sidekiq::ScheduledSet.new.select do |job|
job.args.first['job_class'] == 'DomainDeleteJob' && job.args.first['arguments'] == [id]
end
jobs.each(&:delete)
end

def deletion_time_span
Expand Down
4 changes: 0 additions & 4 deletions app/models/que_job.rb

This file was deleted.

3 changes: 1 addition & 2 deletions test/interactions/expire_period/start_test.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'test_helper'
require 'sidekiq/testing'

class StartTest < ActiveSupport::TestCase
include ActionMailer::TestHelper
Expand All @@ -11,7 +10,7 @@ class StartTest < ActiveSupport::TestCase
end

def test_sets_expired
Sidekiq::Testing.inline! do
Sidekiq::Testing.fake! do
perform_enqueued_jobs do
DomainCron.start_expire_period
end
Expand Down
13 changes: 6 additions & 7 deletions test/models/domain/releasable/discardable_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'test_helper'
require 'sidekiq/testing'
Sidekiq::Testing.fake!

class DomainReleasableDiscardableTest < ActiveSupport::TestCase
include ActiveJob::TestHelper
Expand Down Expand Up @@ -44,11 +46,7 @@ def test_ignores_already_discarded_domains

Domain.release_domains

job_count = lambda do
QueJob.where("args->>0 = '#{@domain.id}'", job_class: DomainDeleteJob.name).count
end

assert_no_difference job_count, 'A domain should not be discarded again' do
assert_no_enqueued_jobs do
Domain.release_domains
end
end
Expand Down Expand Up @@ -104,7 +102,8 @@ def test_keeping_a_domain_bypasses_validation

def test_keeping_a_domain_cancels_domain_deletion
@domain.update!(statuses: [DomainStatus::DELETE_CANDIDATE])
@domain.keep
assert_nil QueJob.find_by("args->>0 = '#{@domain.id}'", job_class: DomainDeleteJob.name)
assert_no_enqueued_jobs only: DomainDeleteJob do
@domain.keep
end
end
end
3 changes: 3 additions & 0 deletions test/system/admin_area/domains_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
require 'application_system_test_case'
require 'sidekiq/testing'

Sidekiq::Testing.fake!

class AdminDomainsTestTest < ApplicationSystemTestCase
setup do
Expand Down
3 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
require 'capybara/minitest'
require 'webmock/minitest'
require 'support/assertions/epp_assertions'
require 'sidekiq/testing'

Sidekiq::Testing.fake!


# `bin/rails test` is not the same as `bin/rake test`.
Expand Down

0 comments on commit b24023c

Please sign in to comment.