Created
December 4, 2013 05:54
-
-
Save pianosnake/7783023 to your computer and use it in GitHub Desktop.
Basic Ruby script to listen for Postgres notifications from a central database and update a client database.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'sequel' | |
| require 'json' | |
| require 'pg' | |
| DB_central = Sequel.connect('postgres://xxx:xxx@hostname/central_db') | |
| DB_client1 = Sequel.connect('postgres://xxx:xxx@hostname/client1_db') | |
| DB_central.listen :usersupdate, {loop: true} do |channel, pid, payload| | |
| puts "#{channel} -- #{pid} -- #{payload}" | |
| j = JSON.parse(payload) | |
| if j && j["id"] | |
| DB_client1. | |
| from(:users). | |
| where(id: j["id"]). | |
| update(email: j["email"], name: j["name"]) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment