def __new__(cls, deployment_config: str = None): if not deployment_config and None in cls._instances: return cls._instances[None] try: path = os.path.abspath(cls.find_file(deployment_config)) except TypeError: raise ValueError("Environment Variable QUETZ_CONFIG_FILE \ should be set to name / path of the config file") if path not in cls._instances: config = super().__new__(cls) config.init(path) cls._instances[path] = config # optimization - for default config path we also store the instance # under None key if not deployment_config: cls._instances[None] = config return cls._instances[path]
async def aquarium_main_task( app: FastAPI, config: Config, kvstore: KV, gstate: GlobalState, nodemgr: NodeMgr, deployment: DeploymentMgr, ) -> None: logger.debug("Starting main Aquarium task.") app.state.deployment = deployment app.state.nodemgr = nodemgr while not _shutting_down and not deployment.installed: logger.debug("Waiting for node to be installed.") await asyncio.sleep(1.0) if _shutting_down: return assert deployment.installed try: await deployment.init() except InitError as e: logger.error(f"Unable to init node: {e.message}") sys.exit(1) logger.info("Init Node Manager.") config.init() kvstore.init() gstate_init(gstate, nodemgr) nodemgr.init() logger.info("Starting Node Manager.") await nodemgr.start() await gstate.start() logger.info("Post-Init Deployment.") deployment.postinit(gstate, nodemgr) app.state.gstate = gstate
def get_config() -> Dict[str, Union[str, bool]]: """Get the application configuration.""" config.init(context.config.get_main_option("app.cfg")) settings: Dict[str, Union[str, bool]] = {} settings.update(config.get_config()) alembic_name = context.config.get_main_option("type") schema_config_name = "schema{}".format( f"_{alembic_name}" if alembic_name != "main" else "") script_location = context.config.get_main_option("script_location") version_table = context.config.get_main_option("version_table") version_locations = context.config.get_main_option("version_locations") assert script_location assert version_table assert version_locations settings.update({ "script_location": script_location, "version_table": version_table, "version_locations": version_locations, "version_table_schema": config[schema_config_name], }) return settings
num_entries = int(opts.num_entries) num_instances = int(opts.num_instances) gzip_body = not opts.nogzip begin = datetime.now(tzutc()) if opts.begin: try: begin = datetime.strptime(opts.begin, '%Y-%m-%d') except Exception, e: print "Unable to parse: %s" % (opts.begin) print "Caught exception: %s" % (e) sys.exit(1) begin = begin.replace(tzinfo=tzutc()) print "Will create %s entries for %s instances beginning at: %s" % (num_entries, num_instances, begin) # Init db connection and splice classes config.init(settings.SPLICE_CONFIG_FILE) init_logging() # Redo logging config so we can control where we log data for these runs # Populate system facts start_a = time.time() init_instance_identifiers(num_instances) init_facts(num_instances) start_b = time.time() # Create checkin data data = create_data(num_instances, num_entries, begin=begin) end = time.time() print "\nCreated %s MarketingProductUsage objects for %s instances each having %s checkins" % (len(data), num_instances, num_entries) print "%.3f seconds to create simulated data, %.3f seconds to init system facts, %.3f seconds to generate checkins" % \ (end-start_a, start_b-start_a, end-start_b) start = time.time() # Send data to server send(host, port, url, data, gzip_body=gzip_body)
] if not (len(codes) == len(lb) and len(lb) == len(ub)): abort(404, message="codes,lb,ub 's length must align") if not isinstance(args['base'], list): args['base'] = args['base'].split(',') args['codes'] = args['codes'].split(',') args['lb'] = args['lb'].split(',') args['ub'] = args['ub'].split(',') return args ## ## Actually setup the Api resource routing here ## api.add_resource(MVBacktest, '/backtest') if __name__ == '__main__': import sys if len(sys.argv) != 2: print('use: python api.py [dev|test|prod]来启动程序') #初始化日志配置 if not os.path.exists("logs"): os.makedirs("logs") logging.config.fileConfig('conf/log.prop') #初始化环境配置 filename = "conf/config_%s.cfg" % sys.argv[1] config.init(filename) app.run(host='0.0.0.0', debug=True)
def configure(profile=None): """Central configuration entrypoint.""" profile = profile if profile else os.getenv("IOT_SERVER_PROFILE", "test") config.init(profile) configure_database() configure_routes()