demarches-normaliennes/app/jobs/web_hook_job.rb

25 lines
667 B
Ruby
Raw Normal View History

2018-03-01 17:04:05 +01:00
class WebHookJob < ApplicationJob
2020-09-22 17:14:31 +02:00
queue_as :webhooks_v1
2018-03-01 17:04:05 +01:00
TIMEOUT = 10
def perform(procedure_id, dossier_id, state, updated_at)
2018-03-01 17:04:05 +01:00
body = {
procedure_id: procedure_id,
dossier_id: dossier_id,
state: state,
updated_at: updated_at
2018-03-01 17:04:05 +01:00
}
2023-10-09 09:21:43 +02:00
procedure = Procedure.find(procedure_id)
2023-10-09 09:21:43 +02:00
response = Typhoeus.post(procedure.web_hook_url, body: body, timeout: TIMEOUT)
if !response.success?
Sentry.set_tags(procedure: procedure_id, dossier: dossier_id)
Sentry.set_extras(web_hook_url: procedure.web_hook_url)
Sentry.capture_message("Webhook error: #{response.status} // Response: #{response.body}")
end
2018-03-01 17:04:05 +01:00
end
end