Skip to content

Commit

Permalink
http_server: Support Async 2.0 gem
Browse files Browse the repository at this point in the history
Signed-off-by: Takuro Ashie <[email protected]>
  • Loading branch information
ashie committed Aug 3, 2022
1 parent cf241f0 commit 061f39c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 0 additions & 1 deletion fluentd.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@ Gem::Specification.new do |gem|
gem.add_development_dependency("test-unit", ["~> 3.3"])
gem.add_development_dependency("test-unit-rr", ["~> 1.0"])
gem.add_development_dependency("oj", [">= 2.14", "< 4"])
gem.add_development_dependency("async", "~> 1.23")
gem.add_development_dependency("async-http", ">= 0.50.0")
end
14 changes: 8 additions & 6 deletions lib/fluent/plugin_helper/http_server/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def initialize(addr:, port:, logger:, default_app: nil, tls_context: nil)
scheme = tls_context ? 'https' : 'http'
@uri = URI("#{scheme}://#{@addr}:#{@port}").to_s
@router = Router.new(default_app)
@reactor = Async::Reactor.new(nil, logger: @logger)
@server_task = nil
Console.logger = @logger

opts = if tls_context
{ ssl_context: tls_context }
Expand All @@ -54,23 +55,24 @@ def initialize(addr:, port:, logger:, default_app: nil, tls_context: nil)

def start(notify = nil)
@logger.debug("Start async HTTP server listening #{@uri}")
task = @reactor.run do
@server.run

Async do |task|
@server_task = task.async do
@server.run
end
if notify
notify.push(:ready)
end
end

task.stop
@logger.debug('Finished HTTP server')
end

def stop
@logger.debug('closing HTTP server')

if @reactor
@reactor.stop
if @server_task
@server_task.stop
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/plugin_helper/test_http_server_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ def start_https_request(addr, port, verify: true, cert_path: nil, selfsigned: tr
end

client = Async::HTTP::Client.new(Async::HTTP::Endpoint.parse("https://#{addr}:#{port}", ssl_context: context))
reactor = Async::Reactor.new(nil, logger: NULL_LOGGER)
Console.logger = NULL_LOGGER

resp = nil
error = nil

reactor.run do
Async do |task|
begin
response = yield(client)
rescue => e # Async::Reactor rescue all error. handle it by myself
Expand Down

0 comments on commit 061f39c

Please sign in to comment.