Skip to content

Commit

Permalink
fix: gracefully handle situation where webhook is deleted before exec…
Browse files Browse the repository at this point in the history
…ution
  • Loading branch information
bethesque committed May 10, 2019
1 parent 4303e4f commit 634ccd5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/pact_broker/webhooks/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion spec/lib/pact_broker/webhooks/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 634ccd5

Please sign in to comment.