Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

support for wait_for_notify #5

Closed
royaltm opened this Issue · 9 comments

2 participants

royal Brian Kierstead
royal
Owner

wait_for_notify EM version is missing.

Brian Kierstead

What would it take to add this in?

Brian Kierstead

bump

royal
Owner

sorry, I am just overwhelmed by the amount of stuff in my backlog, I'll try to crack it during the weekend.
In the meantime could you gist me with an example of how do you plan to use it? What kind of notifies are you waiting for? How to trigger them for testing, etc.

Brian Kierstead

I want to do this with ruby instead of java: http://blog.databasepatterns.com/2014/04/postgresql-nofify-websocket-spring-mvc.html?utm_source=postgresweekly&utm_medium=email

I found this: http://stackoverflow.com/questions/16405520/postgres-listen-notify-rails but want to do it without the polling.

I have system that transfers data to another system when certain things happen. Right now, it's all managed inside the app. I'd prefer to setup notifiers to handle it with worker, storing the messages in redis which we are also using.

I haven't coded anything for this yet.

royal
Owner

Ok, it's ready (I hope) on master branch.

There are actually two methods:

  • nonblocking: wait_for_notify_defer([timeout]) -> Deferrable. The deferrable's succeed is called with a notification hash, the same as PG#notifies returns.
  • fiber blocking: wait_for_notify([timeout]) {|name, pid, payload| ... } -> name. This one has compatible syntax with original blocking implementation.

Please let me know if it works for you.

Brian Kierstead
royal
Owner

the current implementation is however quite fragile: while waiting for notifies there is nothing that will stop you from sending queries on the same connection, but it will make the connection "forget" that you were waiting for notifies. I'll try to re-implement it later to allow querying database safely while waiting for notifies on the same connection.

Brian Kierstead
royal
Owner

New implementation is ready with lots of specs. Waiting for notifications is (almost - query timeout expiration cancels it) completely transparent to running queries. This might be useful if you want to notify and listen to notifications in parallel. To check for self-sent notifications compare :be_pid from notification hash with the result of SELECT pg_backend_pid().

royal royaltm closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.