Example #1
0
    def __init__(self , dbServer, _createBots = True):
#         dbServerAliases =dbServers.keys()
#         defaultConn = dbServers[DEFAULT_SERVER_ALIAS] 
        #print dbServer
        self.dbConnection = connect('quizApp',host= dbServer[0], port = dbServer[1])
            
#         for i in dbServerAliases:
#             if(i!=DEFAULT_SERVER_ALIAS):
#                 db =connect('quizApp', alias=i, host=dbServers[i][0], port = dbServers[i][1])

        self.dbServer = dbServer
        if(_createBots):
            from CreateBots import createBots
            self._bots = createBots(self, UserWinsLosses)
Example #2
0
def main():
    
    
    global dbUtils
    global routerServer
    global logger
    global HTTP_PORT 



    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("--port", help="display a square of a given number",
                        type=int, required=True)
    
    parser.add_argument("--isFirstInit", help="display a square of a given number",
                        type=bool)
    
    parser.add_argument("--gcmServerAuth", help="gcm key for push notifications",
                        type=str)
    
    
    parser.add_argument("--serverId", help="serverId",
                        type=str, required=True)
    
    parser.add_argument("--serverAddr", help="external ip address ",
                        type=str , required=True)
    
    parser.add_argument("--serverGroup", help="unique to identify group , like main , development-1 etc",
                        type=str)
    
    args = parser.parse_args()
    

    Config.serverGroup = args.serverGroup if args.serverGroup else Config.serverGroup
    Config.serverId = args.serverId
        
    Utils.logger = logger = create_timed_rotating_log('quizapp_logs/quizapp'+"_"+Config.serverId+'.log')
        
    
    
    
    logger.info("PROCESS_PID: "+str(os.getpid()))
    logger.info("initializing dbUtils..")
    Utils.dbUtils  = dbUtils = Db.DbUtils(Config.dbServer)#initialize Db
    
#     if(not args.serverAddr.endswith(str(args.port))):
#         print "Serveradd should end with port, continue only if you have configured domain-name:port to your serving host"
    if(not args.serverAddr.startswith("http")):
        print "Serveraddr should shart with http or https"
        return
    
    if(dbUtils.isServerIdExists(Config.serverId, Config.serverGroup)):
        print "there is already a server entry with the same serverId %s in this group %s clear , if there is no such such server running you can continue"% (Config.serverId, Config.serverGroup)
        if(raw_input("y/n : ").lower()=="n"):
            return
    
    dbUtils.updateServerMap({Config.serverId: args.serverAddr }, Config.serverGroup)
    ##generate a random key and send an email to help manage
    dbUtils.addSecretKey(HelperFunctions.generateKey(10))
        
    logger.info("initialing router utilities")
    Utils.routerServer = routerServer = RouterServerUtils.RouterServerUtils(dbUtils)
    HTTP_PORT = args.port
    if(args.isFirstInit):
        from CreateBots import createBots
        bots = createBots(dbUtils, Db.UserWinsLosses)
        logger.info("creating bots..")
        print bots
        dbUtils.loadBotUids()
        
        if(not args.gcmServerAuth):
            print "You must supply a  gcm key on first init"
            return
        
    if(args.gcmServerAuth):
        dbUtils.config("gcmauth",args.gcmServerAuth)
    
    
    reloadGcmConfig()
            
    

    http_server = tornado.httpserver.HTTPServer(QuizApp())
    http_server.listen(HTTP_PORT)
    ## this should be moved to seperate queuing service
    tornado.ioloop.PeriodicCallback(sendGcmMessages, 2000).start()
    tornado.ioloop.IOLoop.instance().start()