def setUp(self): db.setup('localhost', 'test', 'test', 'nagi', pool_opt={ 'minconn': 3, 'maxconn': 10 }) db.execute('DROP TABLE IF EXISTS `users`') res = db.execute("""CREATE TABLE `users` ( `uid` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(20) NOT NULL, PRIMARY KEY (`uid`))""") rows = [] for _ in range(1, 100): rows.append('(%d , "name_%d")' % (_, _)) db.execute('INSERT INTO users VALUES ' + ', '.join(rows))
def setdebug(debug=False): level = logging.DEBUG if debug else logging.INFO logging.basicConfig(level=level, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filemode='a+') if __name__ == '__main__': setdebug(False) db.setup('localhost', 'test', 'test', 'nagi', pool_opt={ 'minconn': 3, 'maxconn': 10 }) thing_setup() next_run = datetime.now() - timedelta(minutes=10) for cron_id in range(4, 11): name = 'name_' + str(cron_id) job = Job(cron_id, None, name, event='every 2', next_run=next_run) Thing('job').save(job) time.sleep(2) try: cron = Cron(5) cron.run() except KeyboardInterrupt: exit(1)
from nagi import db from random import randint db.setup('localhost', 'test', 'test', 'nagi', pool_opt={'minconn':3, 'maxconn':10}) def create_lb(lid, name='test_3'): r = db.query_one('SELECT lid from leaderboards WHERE name=%s', (name,)) if not r: db.execute('INSERT INTO leaderboards VALUES(%s, %s, "bucket")', (lid, name,)) def make_entries(lid, total=100000): to = 0 rows = [] for uid in range(1, total + 1): data = r'{\"user\": \"user_%d\"}' %(uid) rows.append('(%d, %d, %d, "%s", "2014-08-17 12:49:01")' % (uid, lid, randint(0, 10000), data)) if len(rows) == 500: db.execute('INSERT INTO entries VALUES ' + ', '.join(rows)) rows = [] if rows: db.execute('INSERT INTO entries VALUES ' + ', '.join(rows)) if __name__ == '__main__': for lid in range(4, 11): name = 'name_' + str(lid) print name create_lb(lid, name) make_entries(lid)