Created
May 15, 2026 13:09
-
-
Save devotdev/9ffe67f65775d78c28eb673b8b8c31d3 to your computer and use it in GitHub Desktop.
app/services/partner_api/application.rb - execute_request!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def execute_request!(method, path, body: {}, query: {}) | |
| start_time = Time.current | |
| request_id = SecureRandom.hex(8) | |
| Rails.logger.info("[PartnerApi][#{request_id}][REQUEST] #{method.upcase} #{path}") | |
| response = self.class.public_send( | |
| method, | |
| "#{base_url}#{path}", | |
| headers: default_headers, | |
| body: body.to_json, | |
| query: query, | |
| timeout: @timeout || REQUEST_TIMEOUT, | |
| open_timeout: OPEN_TIMEOUT | |
| ) | |
| duration_ms = ((Time.current - start_time) * 1000).round(2) | |
| Rails.logger.info( | |
| "[PartnerApi][#{request_id}][RESPONSE] #{method.upcase} #{path} " \ | |
| "status=#{response.code} duration=#{duration_ms}ms" | |
| ) | |
| if duration_ms > 5_000 | |
| Slack::Post.perform_later("Slow PartnerApi call: #{method.upcase} #{path} took #{duration_ms}ms") | |
| end | |
| response | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment