diff --git a/lib/pact_broker/webhooks/job.rb b/lib/pact_broker/webhooks/job.rb index 5a3d46d06..2b50bdb8e 100644 --- a/lib/pact_broker/webhooks/job.rb +++ b/lib/pact_broker/webhooks/job.rb @@ -18,11 +18,20 @@ def perform data private - attr_reader :triggered_webhook, :error_count + attr_reader :triggered_webhook, :error_count, :data def perform_with_connection(data) @data = data - @triggered_webhook = PactBroker::Webhooks::TriggeredWebhook.find(id: data[:triggered_webhook].id) + triggered_webhook_id = data[:triggered_webhook].id + @triggered_webhook = PactBroker::Webhooks::TriggeredWebhook.find(id: triggered_webhook_id) + if triggered_webhook + perform_with_triggered_webhook + else + logger.info "Could not find webhook with id: #{triggered_webhook_id}" + end + end + + def perform_with_triggered_webhook @error_count = data[:error_count] || 0 begin webhook_execution_result = PactBroker::Webhooks::Service.execute_triggered_webhook_now triggered_webhook, execution_options(data) diff --git a/spec/lib/pact_broker/webhooks/job_spec.rb b/spec/lib/pact_broker/webhooks/job_spec.rb index 560bfbdc0..7c1d0a24b 100644 --- a/spec/lib/pact_broker/webhooks/job_spec.rb +++ b/spec/lib/pact_broker/webhooks/job_spec.rb @@ -26,7 +26,6 @@ module Webhooks end context "when the job succeeds" do - it "does not reschedule the job" do expect(Job).to_not receive(:perform_in) subject @@ -131,6 +130,18 @@ module Webhooks subject end end + + context "when the webhook gets deleted between executions" do + before do + allow(PactBroker::Webhooks::TriggeredWebhook).to receive(:find).and_return(nil) + end + + it "does not reschedule the job" do + expect(Job).to_not receive(:perform_in) + expect(logger).to receive(:info).with(/Could not find webhook with id: 1/) + subject + end + end end end end