From 9b48523ff38af8269bd9a49646b3b11533625f5c Mon Sep 17 00:00:00 2001 From: Eric House Date: Wed, 7 Nov 2012 06:17:33 -0800 Subject: [PATCH] fix to work with new DB scheme and to send json client now expects --- xwords4/relay/scripts/gcm_loop.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/xwords4/relay/scripts/gcm_loop.py b/xwords4/relay/scripts/gcm_loop.py index 23042b3e8..cf5feff43 100755 --- a/xwords4/relay/scripts/gcm_loop.py +++ b/xwords4/relay/scripts/gcm_loop.py @@ -24,14 +24,9 @@ def init(): def get( con ): cur = con.cursor() - cur.execute("SELECT id, devid from msgs where devid != 0") - return cur.fetchall() + cur.execute("SELECT id, devid from msgs where devid != ''") -def asGCMIds(con, devids): - cur = con.cursor() - query = "SELECT devid FROM devices WHERE devtype = 3 AND id IN (%s)" % ",".join([str(y) for y in devids]) - cur.execute( query ) - return [elem[0] for elem in cur.fetchall()] + return cur.fetchall() def notifyGCM( devids ): print "sending for", len(devids), "devices" @@ -53,7 +48,7 @@ def notifyGCM( devids ): # successful mark them as sent. Backoff is based on msgids: if the # only messages a device has pending have been seen before, backoff # applies. -def sendWithBackoff( con, msgs ): +def sendWithBackoff( msgs ): global g_sent targets = [] for row in msgs: @@ -64,8 +59,7 @@ def sendWithBackoff( con, msgs ): g_sent[ msgid ] = True targets.append( devid ) if 0 < len(targets): - devids = asGCMIds( con, targets ) - notifyGCM( devids ) + notifyGCM( targets ) else: print "no new targets found" @@ -94,7 +88,7 @@ g_con = init() while g_con: devids = get( g_con ) if 0 < len(devids): - sendWithBackoff( g_con, devids ) + sendWithBackoff( devids ) pruneSent( devids ) else: print "no messages found" if not g_loop: break