Fixes #3653 - Freshdesk import fails with timeout error.

This commit is contained in:
Martin Gruner 2021-07-14 18:55:57 +00:00
parent ee62e47a87
commit 718899da18
4 changed files with 38 additions and 2 deletions

View file

@ -7,6 +7,11 @@ class ApplicationJob < ActiveJob::Base
ActiveJob::Logging::LogSubscriber.detach_from :active_job
# See config/initializers/delayed_jobs_timeout_per_job.rb for details.
def self.max_run_time
4.hours
end
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked

View file

@ -1,6 +1,12 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
class AsyncImportJob < ApplicationJob
# See config/initializers/delayed_jobs_timeout_per_job.rb for details.
def self.max_run_time
7.days
end
def perform(import_job)
import_job.start
end

View file

@ -0,0 +1,25 @@
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
# Workaround for ActiveJob not supporting per-job timeouts with delayed_job.
#
# delayed_job does support this (https://github.com/collectiveidea/delayed_job#custom-jobs),
# but since ActiveJob's adapter places a JobWrapper class around the jobs, it fails to work.
#
# Solve this by delegating that method to the actual job class instead.
# Set the maximum possible max_run_time for any job to a high value, and set a sensible default
# in ApplicationJob.max_run_time. Then specific jobs like AsyncImportJob can override this with a
# higher value.
Delayed::Worker.max_run_time = 7.days
module ActiveJob
module QueueAdapters
class DelayedJobAdapter
class JobWrapper
def max_run_time
job_data['job_class'].constantize.max_run_time
end
end
end
end
end

View file

@ -15,7 +15,7 @@ class Sequencer
return response if response.is_a? Net::HTTPOK
handle_error response, iteration
rescue => e
rescue Net::HTTPClientError => e
handle_exception e, iteration
end
end
@ -34,7 +34,7 @@ class Sequencer
def handle_exception(e, iteration)
logger.error e
logger.info "Sleeping 10 seconds after #{e.name} and retry (##{iteration + 1}/10)."
logger.info "Sleeping 10 seconds after #{e.class.name} and retry (##{iteration + 1}/10)."
sleep 10
end