lib/pact_broker/webhooks/service.rb in pact_broker-1.18.0 vs lib/pact_broker/webhooks/service.rb in pact_broker-2.0.0.beta.1
- old
+ new
@@ -1,10 +1,8 @@
require 'pact_broker/repositories'
require 'pact_broker/logging'
-require 'pact_broker/webhooks/job'
require 'base64'
-require 'securerandom'
module PactBroker
module Webhooks
class Service
@@ -50,24 +48,25 @@
webhook_repository.find_by_consumer_and_provider consumer, provider
end
def self.execute_webhooks pact
webhooks = webhook_repository.find_by_consumer_and_provider pact.consumer, pact.provider
-
if webhooks.any?
run_later(webhooks)
else
logger.debug "No webhook found for consumer \"#{pact.consumer.name}\" and provider \"#{pact.provider.name}\""
end
end
+ # TODO background job?
def self.run_later webhooks
- webhooks.each do | webhook |
- begin
- logger.info "Scheduling job for #{webhook.description} with uuid #{webhook.uuid}"
- Job.perform_async webhook: webhook
- rescue StandardError => e
- log_error e
+ Thread.new do
+ webhooks.each do | webhook |
+ begin
+ webhook.execute
+ rescue StandardError => e
+ # Exceptions are already logged, no need to log again.
+ end
end
end
end
end
end