mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
fix to work with new DB scheme and to send json client now expects
This commit is contained in:
parent
1e13d6ac6c
commit
9b48523ff3
1 changed files with 5 additions and 11 deletions
|
@ -24,14 +24,9 @@ def init():
|
||||||
|
|
||||||
def get( con ):
|
def get( con ):
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
cur.execute("SELECT id, devid from msgs where devid != 0")
|
cur.execute("SELECT id, devid from msgs where devid != ''")
|
||||||
return cur.fetchall()
|
|
||||||
|
|
||||||
def asGCMIds(con, devids):
|
return cur.fetchall()
|
||||||
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()]
|
|
||||||
|
|
||||||
def notifyGCM( devids ):
|
def notifyGCM( devids ):
|
||||||
print "sending for", len(devids), "devices"
|
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
|
# successful mark them as sent. Backoff is based on msgids: if the
|
||||||
# only messages a device has pending have been seen before, backoff
|
# only messages a device has pending have been seen before, backoff
|
||||||
# applies.
|
# applies.
|
||||||
def sendWithBackoff( con, msgs ):
|
def sendWithBackoff( msgs ):
|
||||||
global g_sent
|
global g_sent
|
||||||
targets = []
|
targets = []
|
||||||
for row in msgs:
|
for row in msgs:
|
||||||
|
@ -64,8 +59,7 @@ def sendWithBackoff( con, msgs ):
|
||||||
g_sent[ msgid ] = True
|
g_sent[ msgid ] = True
|
||||||
targets.append( devid )
|
targets.append( devid )
|
||||||
if 0 < len(targets):
|
if 0 < len(targets):
|
||||||
devids = asGCMIds( con, targets )
|
notifyGCM( targets )
|
||||||
notifyGCM( devids )
|
|
||||||
else:
|
else:
|
||||||
print "no new targets found"
|
print "no new targets found"
|
||||||
|
|
||||||
|
@ -94,7 +88,7 @@ g_con = init()
|
||||||
while g_con:
|
while g_con:
|
||||||
devids = get( g_con )
|
devids = get( g_con )
|
||||||
if 0 < len(devids):
|
if 0 < len(devids):
|
||||||
sendWithBackoff( g_con, devids )
|
sendWithBackoff( devids )
|
||||||
pruneSent( devids )
|
pruneSent( devids )
|
||||||
else: print "no messages found"
|
else: print "no messages found"
|
||||||
if not g_loop: break
|
if not g_loop: break
|
||||||
|
|
Loading…
Add table
Reference in a new issue