def set_redis_connection(): get_redis_connection(current_app.config) redis_connection = getattr(g, "_redis_connection", None) if redis_connection is None: redis_connection = g._redis_connection = get_redis_connection( current_app.config) return redis_connection
def __init__(self, config, puzzle): super().__init__() self.halt = False self.config = config self.puzzle = puzzle self.pubsub = get_redis_connection(self.config, decode_responses=False).pubsub( ignore_subscribe_messages=False ) self.redis_connection = get_redis_connection( self.config, decode_responses=False ) self.now = time.time() self.end = self.now + TTL self.limit = self.now + MAX_TTL self.enable_proximity = bool( len( {"all", "stack_pieces", "max_stack_pieces"}.intersection( self.config["PUZZLE_RULES"] ) ) ) if not self.enable_proximity: self.redis_connection.delete(f"pcstacked:{puzzle}") logger.info(f"Puzzle {puzzle} init now: {self.now}") # setup puzzle bbox index # create pixelated piece mask if needed (puzzle_data, piece_properties, hotspot_idx, proximity_idx, origin_bboxes) = create_index( self.config, self.redis_connection, puzzle ) self.hotspot = enforcer.hotspot.HotSpot( self.redis_connection, hotspot_idx, piece_properties, self.config, ) if self.enable_proximity: self.proximity = enforcer.proximity.Proximity( self.redis_connection, proximity_idx, origin_bboxes, puzzle_data, piece_properties, self.config, )
def __init__(self, config_file, **kw): config = loadConfig(config_file) config.update(kw) logger.setLevel(logging.DEBUG if config["DEBUG"] else logging.INFO) self.halt = False self.config = config self.greenlet_list = [] self.pubsub = get_redis_connection( self.config, decode_responses=False).pubsub(ignore_subscribe_messages=False) self.active_puzzles = set() signal.signal(signal.SIGINT, self.cleanup)
def main(): "" args = docopt(__doc__) config_file = args["--config"] config = loadConfig(config_file) cookie_secret = config.get("SECURE_COOKIE_SECRET") redis_connection = get_redis_connection(config, decode_responses=False) app = make_app(config=config_file, cookie_secret=cookie_secret) with app.app_context(): with Connection(redis_connection): worker = Worker(list(map(Queue, listen))) # If the render process has an exception worker.push_exc_handler(handle_fail) worker.work(with_scheduler=True)
def main(): "" args = docopt(__doc__) config_file = args["--config"] config = loadConfig(config_file) cookie_secret = config.get("SECURE_COOKIE_SECRET") redis_connection = get_redis_connection(config, decode_responses=False) app = make_app(config=config_file, cookie_secret=cookie_secret) with app.app_context(): with Connection(redis_connection): worker = Worker(list(map(Queue, listen))) # TODO: handle exceptions # worker.push_exc_handler(pieceTranslate.handle_piece_error) worker.work()
def redis(self): return get_redis_connection(config)