def broadcast_bet_stats(self, betid=None): query_total_wager = 'select sum(bet_amount) as totalwager from bets;' query_total_bets = 'select count(*) as totalbets from bets;' query_history = 'select bet_id, username, bet_time, bet_amount, payout, game, roll, profit, result from bets order by bet_id desc limit 30;' if betid is not None: query_history = 'select bet_id, username, bet_time, bet_amount, payout, game, roll, profit, result from bets where bet_id = %s;' try: self.db.execute(query_total_wager, cursor_factory=psycopg2.extras.DictCursor, callback=(yield gen.Callback('query_total_wager'))) self.db.execute(query_total_bets, cursor_factory=psycopg2.extras.DictCursor, callback=(yield gen.Callback('query_total_bets'))) if betid is None: self.db.execute(query_history, cursor_factory=psycopg2.extras.DictCursor, callback=(yield gen.Callback('query_history'))) else: self.db.execute(query_history, (betid, ), cursor_factory=psycopg2.extras.DictCursor, callback=(yield gen.Callback('query_history'))) cursor_total_wager, cursor_total_bets, cursor_history = yield momoko.WaitAllOps( ('query_total_wager', 'query_total_bets', 'query_history')) total_wager = cursor_total_wager.fetchone()['totalwager'] total_bets = cursor_total_bets.fetchone()['totalbets'] bet_history = cursor_history.fetchall() msg = '{"type":"%s", "totalWagered":"%s", "totalBets":"%s", "maxBetLimit":"%s", "betHistory":%s}' % ( "stats", total_wager, total_bets, self.server_variables.maxbetlimit, json.dumps(bet_history, default=json_serial)) self.broadcast(self.clients, msg) except Exception: logging.exception()
def func(): qnum = jobs or max(self.pool_size, self.max_size if self.max_size else 0) for i in range(qnum): self.db.execute('SELECT pg_sleep(%s);' % sleep_time, callback=(yield gen.Callback('q%s' % i))) yield momoko.WaitAllOps(["q%s" % i for i in range(qnum)]) self.stop()
def func(): self.db.execute('SELECT asfdsfe;', callback=(yield gen.Callback('q1'))) self.db.execute('SELECT DOES NOT WORK!;', callback=(yield gen.Callback('q2'))) self.db.execute('SELECT 1;', callback=(yield gen.Callback('q3'))) cursor1, cursor2, cursor3 = yield momoko.WaitAllOps( ('q1', 'q2', 'q3')) self.stop()
def func(): self.db.execute('SELECT 1;', callback=(yield gen.Callback('q1'))) self.db.execute('SELECT 2;', callback=(yield gen.Callback('q2'))) self.db.execute('SELECT 3;', callback=(yield gen.Callback('q3'))) cursor1, cursor2, cursor3 = yield momoko.WaitAllOps( ('q1', 'q2', 'q3')) self.assert_equal(cursor1.fetchone(), (1, )) self.assert_equal(cursor2.fetchone(), (2, )) self.assert_equal(cursor3.fetchone(), (3, )) self.stop()
def func(): self.db.getconn(callback=(yield gen.Callback('q1'))) self.db.getconn(callback=(yield gen.Callback('q2'))) self.db.getconn(callback=(yield gen.Callback('q3'))) conn1, conn2, conn3 = yield momoko.WaitAllOps(('q1', 'q2', 'q3')) conn1.execute('SELECT 1;', callback=(yield gen.Callback('q1'))) conn2.execute('SELECT 2;', callback=(yield gen.Callback('q2'))) conn3.execute('SELECT 3;', callback=(yield gen.Callback('q3'))) cursor1, cursor2, cursor3 = yield momoko.WaitAllOps( ('q1', 'q2', 'q3')) self.assert_equal(cursor1.fetchone(), (1, )) self.assert_equal(cursor2.fetchone(), (2, )) self.assert_equal(cursor3.fetchone(), (3, )) for conn in conn1, conn2, conn3: self.db.putconn(conn) self.stop()
def get(self): self.db.execute('SELECT 42, 12, %s, 11;', (25,), callback=(yield gen.Callback('q1'))) self.db.execute('SELECT 42, 12, %s, %s;', (23, 56), callback=(yield gen.Callback('q2'))) self.db.execute('SELECT 465767, 4567, 3454;', callback=(yield gen.Callback('q3'))) # Separately... # cursor1 = yield momoko.WaitOp('q1') # cursor2 = yield momoko.WaitOp('q2') # cursor3 = yield momoko.WaitOp('q3') # Or all at once cursor1, cursor2, cursor3 = yield momoko.WaitAllOps(('q1', 'q2', 'q3')) self.write('Query 1 results: %s<br>' % cursor1.fetchall()) self.write('Query 2 results: %s<br>' % cursor2.fetchall()) self.write('Query 3 results: %s' % cursor3.fetchall()) self.finish()