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

Location of Listener class so it will listen forever #20

Open
augustosamame opened this issue May 12, 2021 · 1 comment
Open

Location of Listener class so it will listen forever #20

augustosamame opened this issue May 12, 2021 · 1 comment

Comments

@augustosamame
Copy link

I'd like to use this gem to handle PG NOTIFYs from another project's db. Seems like an ideal use case. However, I don't understand where I should run the Listener class so it will run forever in my Rails project.
If I run it on demand, with a timeout, it defeats the purpose of "listening" to the PostgreSQL DB's notifys.
I'm using Puma, which is multithreaded so should I just place the Listener Class in an initializer and it will block a single worker? Should I use sidekiq instead?
Thanks in advance on any clarity you can provide.

@augustosamame augustosamame changed the title Location of listener class so it will listen forever Location of Listener class so it will listen forever May 12, 2021
@tjwp
Copy link
Contributor

tjwp commented May 12, 2021

That's a good question. I've only ever used this as part of a separate, long-running process that would run alongside your web process and worker for sidekiq, etc.

For example this gem contains a rake task to run a separate process that will listen to a PG table and enqueue jobs to Sidekiq https:/ezcater/sidekiq_publisher/blob/master/lib/sidekiq_publisher/runner.rb#L19-L28.

It may be possible for you to run the Listener in a Thread in one of your existing processes so that it does not block, but I have not attempted this. If you went with this approach you'd have to consider error handling to ensure that the Listener keeps running and that errors from it do not take down the process.

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

No branches or pull requests

2 participants