Exemple #1
0
    def ready(self):
        """
        Check the service is ready
        """
        if not self.running:
            return False

        try:
            rs = Redis(host=self.running_host, port=self.running_port)
            rs.client_list()
            return True
        except ConnectionError:
            return False
        except Exception as error:
            self.logger.error('Unexpected error: {}'.format(error))
def is_backend_running() -> bool:
    try:
        conn = Redis(host=get_redis_host(),
                     port=int(get_redis_port()),
                     db=int(get_redis_dbnum()),
                     password=get_redis_password())
        conn.client_list()  # Must perform an operation to check connection.
    except ConnectionError as e:
        print("Failed to connect to Redis instance at %s", get_redis_host())
        print(repr(e))
        return False

    conn.close()  # type: ignore

    return True
Exemple #3
0
''' For full text search '''
WHOOSH_BASE = os.path.join(basedir, 'search.db')

'''
    Setup redis caching connection to be used throughout the site. Credentials
    are set in their respective env vars.
'''
REDIS = Redis(host=get_env_variable("DATAVIVA_REDIS_HOST", "localhost"),
         port=get_env_variable("DATAVIVA_REDIS_PORT", 6379),
         password=get_env_variable("DATAVIVA_REDIS_PW", None))
REDIS_CACHE = RedisCache(host=get_env_variable("DATAVIVA_REDIS_HOST", "localhost"),
         port=get_env_variable("DATAVIVA_REDIS_PORT", 6379),
         password=get_env_variable("DATAVIVA_REDIS_PW", None), default_timeout=2591999)

try:
    REDIS.client_list()
except ConnectionError:
    REDIS, REDIS_CACHE = [None]*2

'''
    Oauth tokens set in environment variables from their respecive sources
'''
GOOGLE_OAUTH_ID = get_env_variable("DATAVIVA_OAUTH_GOOGLE_ID")
GOOGLE_OAUTH_SECRET = get_env_variable("DATAVIVA_OAUTH_GOOGLE_SECRET")
TWITTER_OAUTH_ID = get_env_variable("DATAVIVA_OAUTH_TWITTER_ID")
TWITTER_OAUTH_SECRET = get_env_variable("DATAVIVA_OAUTH_TWITTER_SECRET")
FACEBOOK_OAUTH_ID = get_env_variable("DATAVIVA_OAUTH_FACEBOOK_ID")
FACEBOOK_OAUTH_SECRET = get_env_variable("DATAVIVA_OAUTH_FACEBOOK_SECRET")

'''
    Mail credentials to send automatic emails to users
Exemple #4
0
WHOOSH_BASE = os.path.join(basedir, 'search.db')
'''
    Setup redis caching connection to be used throughout the site. Credentials
    are set in their respective env vars.
'''
REDIS = Redis(host=get_env_variable("DATAVIVA_REDIS_HOST", "localhost"),
              port=get_env_variable("DATAVIVA_REDIS_PORT", 6379),
              password=get_env_variable("DATAVIVA_REDIS_PW", None))
REDIS_CACHE = RedisCache(host=get_env_variable("DATAVIVA_REDIS_HOST",
                                               "localhost"),
                         port=get_env_variable("DATAVIVA_REDIS_PORT", 6379),
                         password=get_env_variable("DATAVIVA_REDIS_PW", None),
                         default_timeout=2591999)

try:
    REDIS.client_list()
except ConnectionError:
    REDIS, REDIS_CACHE = [None] * 2
'''
    Oauth tokens set in environment variables from their respecive sources
'''
GOOGLE_OAUTH_ID = get_env_variable("DATAVIVA_OAUTH_GOOGLE_ID")
GOOGLE_OAUTH_SECRET = get_env_variable("DATAVIVA_OAUTH_GOOGLE_SECRET")
TWITTER_OAUTH_ID = get_env_variable("DATAVIVA_OAUTH_TWITTER_ID")
TWITTER_OAUTH_SECRET = get_env_variable("DATAVIVA_OAUTH_TWITTER_SECRET")
FACEBOOK_OAUTH_ID = get_env_variable("DATAVIVA_OAUTH_FACEBOOK_ID")
FACEBOOK_OAUTH_SECRET = get_env_variable("DATAVIVA_OAUTH_FACEBOOK_SECRET")
'''
    Mail credentials to send automatic emails to users
'''
MAIL_SERVER = get_env_variable("DATAVIVA_MAIL_SERVER", 'smtp.gmail.com')
Exemple #5
0
	games_per_thread = math.ceil(games / threads)

	print("\tStarting simulation with %d bots" % len(bots))
	sim_str = "\tSimulating %d games with %d bots per game"
	print(sim_str % (games, bots_per_game))
	print("\tRunning simulation as  %d queued jobs" % threads)
	if len(sys.argv) == 1:
		print("\tFor help running the script, use the -h flag")



	c = Redis(host = "elissa-0", password = password)
	q = Queue(connection = c)

	print("\tCurrently %d worker threads active\n" % (len(c.client_list())-1,))

	t0 = time.time()
	jobs = [q.enqueue(
		run_simulation,
		i, bots_per_game, games_per_thread, bots,
		ttl = 1e6, result_ttl = 1e6, timeout = 1e6
	) for i in range(threads)]
	while any(not job.is_finished for job in jobs):
		finished = sum(job.is_finished for job in jobs)
		print("\r\t%d/%d finished" % (finished, threads), flush = True, end = "")
		time.sleep(0.2)
	results = [job.result for job in jobs]
	print("\r\t%d/%d finished" % (threads, threads), flush = True, end = "")

	# results = [run_simulation(i, bots_per_game, games_per_thread, bots) for i in range(threads)]