Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: support static config for Semian::NetHTTP and Semian::GRPC #350

Open
jychen7 opened this issue Jun 20, 2022 · 0 comments
Open

Feature: support static config for Semian::NetHTTP and Semian::GRPC #350

jychen7 opened this issue Jun 20, 2022 · 0 comments

Comments

@jychen7
Copy link
Contributor

jychen7 commented Jun 20, 2022

Background

MySQL and Redis supports static config, while NetHTTP and GRPC currently only Proc. e.g.

semian/lib/semian/mysql2.rb

Lines 137 to 140 in 1d4b53b

def raw_semian_options
return query_options[:semian] if query_options.key?(:semian)
return query_options["semian"] if query_options.key?("semian")
end

def retrieve_semian_configuration(host, port)
@semian_configuration.call(host, port) if @semian_configuration.respond_to?(:call)
end

def retrieve_semian_configuration(host)
@semian_configuration.call(host) if @semian_configuration.respond_to?(:call)
end

Problem

If pass a static config to NetHTTP and GRPC, semian is disabled because retrieve_semian_configuration returns nil.

Proposal

allow static config if it is not callable

def retrieve_semian_configuration(host, port)
  return @semian_configuration unless @semian_configuration.respond_to?(:call) 

 @semian_configuration.call(host, port)
 end 

Alternative

Add validation to semian_configuration setter, assert whether static config or Proc is expected

def semian_configuration=(configuration)
raise Semian::NetHTTP::SemianConfigurationChangedError unless @semian_configuration.nil?
@semian_configuration = configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants