Cannot run background services independently in Falcon - service blocks Rack app #308
Unanswered
MateuszMydlarz
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Hopefully this gets you on the right track: #!/usr/bin/env falcon-host
require "falcon/environment/rack"
require "async/redis"
service 'localhost' do
include Falcon::Environment::Rack
endpoint {Async::HTTP::Endpoint.parse('http://0.0.0.0:8013')}
end
class MyService < Async::Service::Generic
def setup(container)
container.spawn do |instance|
evaluator = @environment.evaluator
Console.info(self, "Connecting to Redis at", evaluator.redis_endpoint)
Async do
client = Async::Redis::Client.new(evaluator.redis_endpoint)
instance.ready!
client.subscribe 'status' do |context|
Console.info(self, "Subscribed to Redis channel 'status'.")
while response = context.listen
Console.info(self, "Received event:", response)
end
end
end
end
end
end
service "myservice" do
service_class MyService
redis_endpoint {Async::Redis::Endpoint.local}
end |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I’m trying to run a background service in Falcon using async together with a Rack app. The goal is to have a long-running task (e.g. subscribing to Redis with async-redis) that runs alongside the Rack endpoint handler without blocking it.
What I expected:
Falcon should start the Rack app (so HTTP endpoints work as usual).
A background service (e.g. an async task) should run independently and not block the Rack server.
What happens instead:
When I run a background service using Async do ... end, the service blocks Falcon from starting the Rack app.
If I wait for the background task (.wait), the HTTP app never boots.
If I don’t wait for it, the task never seems to run.
Essentially, I can’t get a service to run in the background concurrently with Falcon's Rack integration.
Result:
The Redis subscription service runs, but Falcon does not start the Rack application.
If I remove the Async block part, Falcon runs the Rack app normally, but task never start.
I can’t figure out how to make both work together in the same Falcon process.
falcon.rb:
app.rb:
Beta Was this translation helpful? Give feedback.
All reactions