From f2d92f381eda92949e62814e521b2ff23150754c Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Wed, 6 Sep 2017 13:28:41 +1000 Subject: [PATCH] feat(webhook status): moved webhook retry schedule to configuration --- lib/pact_broker/configuration.rb | 2 ++ lib/pact_broker/webhooks/job.rb | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/pact_broker/configuration.rb b/lib/pact_broker/configuration.rb index a1753007d..eb4018b73 100644 --- a/lib/pact_broker/configuration.rb +++ b/lib/pact_broker/configuration.rb @@ -18,6 +18,7 @@ class Configuration attr_accessor :use_case_sensitive_resource_names, :order_versions_by_date attr_accessor :semver_formats attr_accessor :enable_badge_resources, :shields_io_base_url + attr_accessor :webhook_retry_schedule attr_writer :logger def initialize @@ -48,6 +49,7 @@ def self.default_configuration # consistently extract an orderable object from the consumer application version number. config.order_versions_by_date = false config.semver_formats = ["%M.%m.%p%s%d","%M.%m", "%M"] + config.webhook_retry_schedule = [10, 60, 120, 300, 600, 1200] #10 sec, 1 min, 2 min, 5 min, 10 min, 20 min => 38 minutes config end diff --git a/lib/pact_broker/webhooks/job.rb b/lib/pact_broker/webhooks/job.rb index c5248df07..4c752976b 100644 --- a/lib/pact_broker/webhooks/job.rb +++ b/lib/pact_broker/webhooks/job.rb @@ -6,8 +6,6 @@ module PactBroker module Webhooks class Job - BACKOFF_TIMES = [10, 60, 120, 300, 600, 1200] #10 sec, 1 min, 2 min, 5 min, 10 min, 20 min => 38 minutes - include SuckerPunch::Job include PactBroker::Logging @@ -45,23 +43,31 @@ def handle_failure reschedule_job update_triggered_webhook_status TriggeredWebhook::STATUS_RETRYING else - logger.error "Failed to execute webhook #{triggered_webhook.webhook_uuid} after #{BACKOFF_TIMES.size} times." + logger.error "Failed to execute webhook #{triggered_webhook.webhook_uuid} after #{retry_schedule.size} times." update_triggered_webhook_status TriggeredWebhook::STATUS_FAILURE end end def reschedule_job? - error_count < BACKOFF_TIMES.size + error_count < retry_schedule.size end def reschedule_job - logger.debug "Re-enqeuing job for webhook #{triggered_webhook.webhook_uuid} to run in #{BACKOFF_TIMES[error_count]} seconds" - Job.perform_in(BACKOFF_TIMES[error_count], @data.merge(error_count: error_count+1)) + logger.debug "Re-enqeuing job for webhook #{triggered_webhook.webhook_uuid} to run in #{retry_schedule[error_count]} seconds" + Job.perform_in(backoff_time, @data.merge(error_count: error_count+1)) end def update_triggered_webhook_status status PactBroker::Webhooks::Service.update_triggered_webhook_status triggered_webhook, status end + + def backoff_time + retry_schedule[error_count] + end + + def retry_schedule + PactBroker.configuration.webhook_retry_schedule + end end end end