Guest User

Untitled

a guest
Jan 14th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. require "rubygems"
  2. require "bundler/setup"
  3. require "sequel"
  4.  
  5. class Listener
  6. def initialize(db, message)
  7. @db = db
  8. @message = message
  9. end
  10.  
  11. def perform(&b)
  12. @db.pool.hold do |connection|
  13. statement = connection.create_statement
  14. statement.execute("LISTEN #{@message}")
  15. statement.close
  16.  
  17. while true do
  18. statement = connection.create_statement
  19. results = statement.execute_query("SELECT 1")
  20. results.close
  21. statement.close
  22.  
  23. notifications = connection.notifications
  24. if notifications && !notifications.empty?
  25. notifications.each do |notification|
  26. b.call
  27. end
  28. end
  29.  
  30. sleep(1)
  31. end
  32. end
  33. end
  34. end
  35.  
  36. DB = Sequel.connect("jdbc:postgresql://stage.db.internal/myapp?user=sam")
  37. $l = Listener.new(DB, "content_ingest_file_uploaded")
Add Comment
Please, Sign In to add comment