Skip to content

Commit

Permalink
add sentry context to webhook call
Browse files Browse the repository at this point in the history
  • Loading branch information
krichtof committed Oct 9, 2023
1 parent 4750e4a commit 21df9f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/jobs/web_hook_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ def perform(procedure_id, dossier_id, state, updated_at)
state: state,
updated_at: updated_at
}

procedure = Procedure.find(procedure_id)
Typhoeus.post(procedure.web_hook_url, body: body, timeout: TIMEOUT)

Sentry.configure_scope do |scope|
scope.set_tags(procedure: procedure_id)
scope.set_tags(dossier: dossier_id)
scope.set_extras(web_hook_url: procedure.web_hook_url)
end

response = Typhoeus.post(procedure.web_hook_url, body: body, timeout: TIMEOUT)

raise StandardError, response if !response.success?
end
end
22 changes: 22 additions & 0 deletions spec/jobs/web_hook_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
describe WebHookJob, type: :job do
describe 'perform' do
let(:procedure) { create(:procedure, web_hook_url:) }
let(:dossier) { create(:dossier, procedure:) }
let(:web_hook_url) { "https://domaine.fr/callback_url" }
let(:job) { WebHookJob.new(procedure.id, dossier.id, dossier.state, dossier.updated_at) }

context 'with success on webhook' do
it 'calls webhook' do
stub_request(:post, web_hook_url).to_return(status: 200, body: "success")
expect { job.perform_now }.not_to raise_error
end
end

context 'with error on webhook' do
it 'raises' do
stub_request(:post, web_hook_url).to_return(status: 500, body: "error")
expect { job.perform_now }.to raise_error
end
end
end
end

0 comments on commit 21df9f3

Please sign in to comment.