Last active
August 29, 2015 14:19
-
-
Save danshev/557000a1f8056daba7e7 to your computer and use it in GitHub Desktop.
Server-side monitoring for the dispatch queue.
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
# 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