Replies: 1 comment
-
Falcon is the front end application server, it's not designed for embedding, but it's made up of components you can embed. You have two options:
There are some limits to the latter, e.g. scaling up using multiple processes, etc. I'm going that isn't a problem for you. As such, the simplest option is to run your entire program within Async and have a separate async task for your server, e.g. require "async"
require "async/http/server"
require "async/http/endpoint"
protocol = Async::HTTP::Protocol::HTTP2
endpoint = Async::HTTP::Endpoint.parse("http://127.0.0.1:9222", reuse_port: true)
Async do
server_task = Async do
server = Async::HTTP::Server.for(endpoint, protocol: protocol) do |request|
Protocol::HTTP::Response[200, {}, request.body]
end
server.run
end
# Main program.
end You can stop the server by calling In order to host a Sinatra app, you will need to use I assume for Sinatra it will be something like |
Beta Was this translation helpful? Give feedback.
-
I'm building a ruby gem that does a bunch of things in separate threads, basically some IO stream processing. I want to embed a sinatra app using falcon in my application to provide an API for getting things like metrics and statistics from the stream processing part of the app. So the main entry point isn't
falcon serve
or the like. I'm runningruby my_app
so that I can set up all the threads for the whole thing, including the web API thread. Basically, the web API isn't the main thing.I also want to get a reference to the embedded web API server so that I can signal to it when it's time to shutdown for a graceful shutdown, or check on it's status, etc.
The only similar search result I've found for this type of thing is here, but it uses EventMachine and thin, neither of which I want to use. Also, all the examples I can find for using sinatra and/or falcon assume the web app is the main concern.
What's the best to accomplish this?
Beta Was this translation helpful? Give feedback.
All reactions