diff --git a/app/jobs/csync_job.rb b/app/jobs/csync_job.rb index 32fc1abcd..1a703a380 100644 --- a/app/jobs/csync_job.rb +++ b/app/jobs/csync_job.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true -class CsyncJob < Que::Job - def run(generate: false) +class CsyncJob < ApplicationJob + def perform(generate: false) @store = {} @input_store = { secure: {}, insecure: {} } @results = {} diff --git a/db/data/20210405081552_migrate_que_jobs.rb b/db/data/20210405081552_migrate_que_jobs.rb new file mode 100644 index 000000000..f7a667799 --- /dev/null +++ b/db/data/20210405081552_migrate_que_jobs.rb @@ -0,0 +1,17 @@ +class MigrateQueJobs < ActiveRecord::Migration[6.0] + def up + QueJob.all.each do |job| + next if job.last_error.present? + + klass = job.job_class.constantize + next unless klass < ApplicationJob + + args = job.args + klass.perform_later(args) + end + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/test/jobs/csync_job_test.rb b/test/jobs/csync_job_test.rb index 8819fd5c7..8254b3da9 100644 --- a/test/jobs/csync_job_test.rb +++ b/test/jobs/csync_job_test.rb @@ -14,14 +14,14 @@ class CsyncJobTest < ActiveSupport::TestCase expected_contents = "[secure]\nns1.bestnames.test shop.test\nns2.bestnames.test shop.test\n" \ "[insecure]\nns1.bestnames.test airport.test metro.test\nns2.bestnames.test airport.test\n" - CsyncJob.run(generate: true) + CsyncJob.perform_now(generate: true) assert_equal expected_contents, IO.read(ENV['cdns_scanner_input_file']) end def test_creates_csync_record_when_new_cdnskey_discovered assert_nil @domain.csync_record - CsyncJob.run + CsyncJob.perform_now @domain.reload assert @domain.csync_record @@ -35,7 +35,7 @@ class CsyncJobTest < ActiveSupport::TestCase def test_creates_dnskey_after_required_cycles assert_equal 0, @domain.dnskeys.count assert_nil @domain.csync_record - CsyncJob.run # Creates initial CsyncRecord for domain + CsyncJob.perform_now # Creates initial CsyncRecord for domain @domain.reload assert @domain.csync_record.present? @@ -46,7 +46,7 @@ class CsyncJobTest < ActiveSupport::TestCase CsyncRecord.stub :by_domain_name, @domain.csync_record do @domain.csync_record.stub :dnssec_validates?, true do - CsyncJob.run + CsyncJob.perform_now end end @@ -58,13 +58,13 @@ class CsyncJobTest < ActiveSupport::TestCase def test_sends_mail_to_contacts_if_dnskey_updated assert_emails 1 do - CsyncJob.run + CsyncJob.perform_now @domain.reload CsyncRecord.stub :by_domain_name, @domain.csync_record do @domain.csync_record.stub :dnssec_validates?, true do 2.times do - CsyncJob.run + CsyncJob.perform_now end end end