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
| ArchiveUser.call(user:) |
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
| user.update!( | |
| archived: true, | |
| archived_at: Time.current | |
| ) |
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
| Project Task | |
| │ | |
| ▼ | |
| Understand requirements | |
| │ | |
| ▼ | |
| Identify unknowns | |
| │ | |
| ▼ | |
| Implementation planning |
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, |
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
| require 'benchmark' | |
| require 'connection_pool' | |
| require 'net/http/persistent' | |
| URL = URI('https://example.com/healthcheck') | |
| N = 100 | |
| Benchmark.bm(22) do |x| | |
| x.report('fresh client per call') do | |
| N.times do |
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
| module PartnerApi | |
| class Orders | |
| def show(id) | |
| PARTNER_API_POOL.with do |client| | |
| response = client.get("/api/v1/orders/#{id}", headers: auth_headers) | |
| JSON.parse(response.body) | |
| end | |
| end | |
| private |
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
| require 'connection_pool' | |
| POOL_SIZE = ENV.fetch('PARTNER_API_POOL_SIZE', 10).to_i | |
| POOL_TIMEOUT = ENV.fetch('PARTNER_API_POOL_TIMEOUT', 5).to_i | |
| PARTNER_API_POOL = ConnectionPool.new(size: POOL_SIZE, timeout: POOL_TIMEOUT) do | |
| PartnerApi::Client.new(base_url: ENV.fetch('PARTNER_API_BASE_URL')) | |
| end |
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
| require 'net/http/persistent' | |
| module PartnerApi | |
| class Client | |
| def initialize(base_url:) | |
| @base_url = base_url | |
| @http = Net::HTTP::Persistent.new(name: 'partner_api') | |
| @http.open_timeout = ENV.fetch('PARTNER_API_OPEN_TIMEOUT', 5).to_i | |
| @http.read_timeout = ENV.fetch('PARTNER_API_REQUEST_TIMEOUT', 15).to_i | |
| end |
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
| gem 'httparty', '~> 0.19.0' | |
| gem 'connection_pool', '~> 2.5' |
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
| module PartnerApi | |
| class Application | |
| class NetTimeout < StandardError; end | |
| include HTTParty | |
| REQUEST_TIMEOUT = ENV.fetch('PARTNER_API_REQUEST_TIMEOUT', 15).to_i | |
| OPEN_TIMEOUT = ENV.fetch('PARTNER_API_OPEN_TIMEOUT', 5).to_i | |
| attr_reader :token |
NewerOlder