20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/services/spree/webhooks/deliver_webhook.rb', line 20
def call
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
response = make_request
execution_time = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000).round
@delivery.complete!(
response_code: response.code.to_i,
execution_time: execution_time,
response_body: response.body.to_s.truncate(10_000)
)
rescue Net::OpenTimeout, Net::ReadTimeout => e
execution_time = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000).round
Rails.error.report(e, context: { webhook_delivery_id: @delivery.id, url: @delivery.url })
@delivery.complete!(
execution_time: execution_time,
error_type: 'timeout',
request_errors: e.message
)
rescue StandardError => e
execution_time = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time) * 1000).round
Rails.error.report(e, context: { webhook_delivery_id: @delivery.id, url: @delivery.url })
@delivery.complete!(
execution_time: execution_time,
error_type: 'connection_error',
request_errors: e.message
)
end
|