fix to work with new DB scheme and to send json client now expects

This commit is contained in:
Eric House 2012-11-07 06:17:33 -08:00
parent 1e13d6ac6c
commit 9b48523ff3

View file

@ -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