mirror of
https://github.com/Evolix/chexpire.git
synced 2024-04-29 23:40:49 +02:00
Merge branch 'hotfix'
This commit is contained in:
commit
730b70c08e
|
@ -1,2 +1,22 @@
|
||||||
class ApplicationJob < ActiveJob::Base
|
class ApplicationJob < ActiveJob::Base
|
||||||
|
# from http://api.rubyonrails.org/classes/ActiveJob/Core.html
|
||||||
|
attr_writer :attempt_number
|
||||||
|
|
||||||
|
def attempt_number
|
||||||
|
@attempt_number ||= 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def serialize
|
||||||
|
super.merge("attempt_number" => attempt_number + 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def deserialize(job_data)
|
||||||
|
super
|
||||||
|
self.attempt_number = job_data["attempt_number"]
|
||||||
|
end
|
||||||
|
|
||||||
|
rescue_from(Timeout::Error) do
|
||||||
|
raise if attempt_number > 5 # rubocop:disable Style/SignalException
|
||||||
|
retry_job(wait: 10)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
18
app/jobs/resync_job.rb
Normal file
18
app/jobs/resync_job.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
class ResyncJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
|
||||||
|
rescue_from ActiveRecord::RecordNotFound do
|
||||||
|
raise if attempt_number == 5 # rubocop:disable Style/SignalException
|
||||||
|
|
||||||
|
# at job creation, the db could not return immediately the check
|
||||||
|
# we have to wait a few (milli)-seconds
|
||||||
|
retry_job(wait: attempt_number**2)
|
||||||
|
end
|
||||||
|
|
||||||
|
def perform(check_id)
|
||||||
|
check = Check.find(check_id)
|
||||||
|
|
||||||
|
WhoisSyncJob.perform_later(check_id) if check.domain?
|
||||||
|
SSLSyncJob.perform_later(check_id) if check.ssl?
|
||||||
|
end
|
||||||
|
end
|
|
@ -100,8 +100,7 @@ class Check < ApplicationRecord
|
||||||
return unless active?
|
return unless active?
|
||||||
return unless saved_changes.key?("domain")
|
return unless saved_changes.key?("domain")
|
||||||
|
|
||||||
WhoisSyncJob.perform_later(id) if domain?
|
ResyncJob.perform_later(id)
|
||||||
SSLSyncJob.perform_later(id) if ssl?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_notifications
|
def reset_notifications
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
<td class="action text-right">
|
<td class="action text-right">
|
||||||
<%= link_to edit_check_path(check) do %>
|
<%= link_to edit_check_path(check), "data-turbolinks" => false do %>
|
||||||
<%== Octicons::Octicon.new("pencil").to_svg %>
|
<%== Octicons::Octicon.new("pencil").to_svg %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
|
|
31
test/jobs/resync_job_test.rb
Normal file
31
test/jobs/resync_job_test.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class ReyncJobTest < ActiveJob::TestCase
|
||||||
|
test "enqueue a whois sync job" do
|
||||||
|
check = create(:check, :domain)
|
||||||
|
|
||||||
|
assert_enqueued_with(job: WhoisSyncJob, args: [check.id]) do
|
||||||
|
ResyncJob.perform_now(check.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "enqueue a ssl sync job" do
|
||||||
|
check = create(:check, :ssl)
|
||||||
|
|
||||||
|
assert_enqueued_with(job: SSLSyncJob, args: [check.id]) do
|
||||||
|
ResyncJob.perform_now(check.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "re enqueued job 5 times when check was not found" do
|
||||||
|
assert_enqueued_jobs 0
|
||||||
|
|
||||||
|
perform_enqueued_jobs(only: ResyncJob) do
|
||||||
|
assert_raise ActiveRecord::RecordNotFound do
|
||||||
|
ResyncJob.perform_now(9999)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_performed_jobs 5, only: ResyncJob
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue