2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-01 17:04:05 +01:00
|
|
|
class WebHookJob < ApplicationJob
|
2024-09-24 20:58:26 +02:00
|
|
|
queue_as :default
|
2020-09-22 17:14:31 +02:00
|
|
|
|
2018-03-01 17:04:05 +01:00
|
|
|
TIMEOUT = 10
|
|
|
|
|
2022-06-01 15:03:31 +02:00
|
|
|
def perform(procedure_id, dossier_id, state, updated_at)
|
2018-03-01 17:04:05 +01:00
|
|
|
body = {
|
2022-06-01 15:03:31 +02:00
|
|
|
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
|
|
|
|
2022-06-10 17:28:07 +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)
|
2023-10-10 09:46:28 +02:00
|
|
|
Sentry.capture_message("Webhook error code: #{response.code} (#{response.return_message}) // Response: #{response.body}")
|
2023-10-09 09:21:43 +02:00
|
|
|
end
|
2018-03-01 17:04:05 +01:00
|
|
|
end
|
|
|
|
end
|