Skip to content

Instantly share code, notes, and snippets.

@danshev
Last active August 29, 2015 14:19
Show Gist options
  • Save danshev/557000a1f8056daba7e7 to your computer and use it in GitHub Desktop.
Save danshev/557000a1f8056daba7e7 to your computer and use it in GitHub Desktop.
Server-side monitoring for the dispatch queue.
# Dependency: https://github.com/hashme/firebase-python
# Use with: https://gist.github.com/danshev/4227f07e5859a30e6304
import firebase
import json
from pprint import pprint # function which pretty prints objects
URL = firebase.firebaseURL('therenow/{0}/dispatch-queue'.format(current_app.config["MARKET_DOMAIN_SLUG"]))
def delete_message(path):
messageURL = firebase.firebaseURL('therenow/{0}/dispatch-queue/{1}'.format(current_app.config["MARKET_DOMAIN_SLUG"], path))
firebase.put(messageURL, None)
def dispatch_message(change):
method = change[0]
messagePath = change[1]["path"][1:]
messageData = change[1]["data"]
if messageData is not None:
if "senderId" in messageData and "message" in messageData and "roomId" in messageData and "recipientId" in messageData:
senderId = messageData["senderId"]
message = messageData["message"]
roomId = messageData["roomId"]
recipientId = messageData["recipientId"]
# look up users (get name, etc)
print message
# send push notification to recipient with roomId in the meta-data
# delete the node
delete_message(messagePath)
S = firebase.subscriber(URL, dispatch_message)
S.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment