def run_gunicorn(): config = get_config() # configure prometheus_client early as possible if pkg_is_installed('prometheus-client'): # Early throw-away parsing of gunicorn config, as we need to decide # whether to enable prometheus multiprocess before we start importing from gunicorn.app.wsgiapp import WSGIApplication g_cfg = WSGIApplication().cfg if g_cfg.workers > 1 or 'prometheus_multiproc_dir' in os.environ: from talisker.prometheus import setup_prometheus_multiproc async_workers = ('gevent', 'eventlet') # must be done before prometheus_client is imported *anywhere* setup_prometheus_multiproc( any(n in g_cfg.worker_class_str for n in async_workers) ) initialise() import talisker.gunicorn if pkg_is_installed('celery'): import talisker.celery talisker.celery.enable_signals() app = talisker.gunicorn.TaliskerApplication( "%(prog)s [OPTIONS] [APP_MODULE]", config.devel, config.debuglog) clear_contexts() return app.run()
def run_help(): """ Usage: talisker.help [CONFIG NAME] Talisker provides some executable wrappers, which initialise Talisker and then simply pass through any supplied arguments to underlying command. - talisker.gunicorn wraps the regular gunicorn invocation - talisker.celery wraps the celery command - talisker.run wraps a regular call to python, and takes a script to run Talisker can be configured by the environment variables listed below. These variable can also be supplied in a python file, although environment variables override any file configuration. """ width = 80 indent = 30 rest = width - indent indent_str = '\n' + ' ' * indent metadata = get_config().metadata() if len(sys.argv) > 1: name = sys.argv[1] if name.upper() not in metadata: sys.stderr.write('Invalid config: {}\n'.format(name)) sys.exit('Invalid config: {}'.format(name)) doc = metadata[name].doc if doc is None: short = 'No documentation' long = [] else: short, long = format_docstring(doc, width) print(name) print() print('\n'.join(short)) print() if long: print('\n'.join(long)) print() else: # print header print(textwrap.dedent(run_help.__doc__).lstrip()) print() for name, meta in metadata.items(): if meta.doc is not None: short, long = format_docstring(meta.doc, rest) print('{:{indent}}{}'.format( name, indent_str.join(short), indent=indent) )
def run_help(): """ Usage: talisker.help [CONFIG NAME] Talisker provides some executable wrappers, which initialise Talisker and then simply pass through any supplied arguments to underlying command. - talisker.gunicorn wraps the regular gunicorn invocation - talisker.celery wraps the celery command - talisker.run wraps a regular call to python, and takes a script to run Talisker can be configured by the environment variables listed below. These variable can also be supplied in a python file, although environment variables override any file configuration. """ width = 80 indent = 30 rest = width - indent indent_str = '\n' + ' ' * indent metadata = get_config().metadata() if len(sys.argv) > 1: name = sys.argv[1] if name.upper() not in metadata: sys.stderr.write('Invalid config: {}\n'.format(name)) sys.exit('Invalid config: {}'.format(name)) doc = metadata[name].doc if doc is None: short = 'No documentation' long = [] else: short, long = format_docstring(doc, width) print(name) print() print('\n'.join(short)) print() if long: print('\n'.join(long)) print() else: # print header print(textwrap.dedent(run_help.__doc__).lstrip()) print() for name, meta in metadata.items(): if meta.doc is not None: short, long = format_docstring(meta.doc, rest) print('{:{indent}}{}'.format(name, indent_str.join(short), indent=indent))
def run_gunicorn(): config = get_config() # Early throw-away parsing of gunicorn config, as we need to decide # whether to enable prometheus multiprocess before we start importing from gunicorn.app.wsgiapp import WSGIApplication g_cfg = WSGIApplication().cfg # configure prometheus_client early as possible if pkg_is_installed('prometheus-client'): if g_cfg.workers > 1 or 'prometheus_multiproc_dir' in os.environ: from talisker.prometheus import setup_prometheus_multiproc async_workers = ('gevent', 'eventlet') # must be done before prometheus_client is imported *anywhere* setup_prometheus_multiproc( any(n in g_cfg.worker_class_str for n in async_workers)) try: from gunicorn.workers.ggevent import GeventWorker from talisker.context import enable_gevent_context except Exception: pass else: if g_cfg.worker_class == GeventWorker: enable_gevent_context() try: from gunicorn.workers.geventlet import EventletWorker from talisker.context import enable_eventlet_context except Exception: pass else: if g_cfg.worker_class == EventletWorker: enable_eventlet_context() initialise() import talisker.gunicorn if pkg_is_installed('celery'): import talisker.celery talisker.celery.enable_signals() app = talisker.gunicorn.TaliskerApplication( "%(prog)s [OPTIONS] [APP_MODULE]", config.devel, config.debuglog) clear_context() return app.run()
def initialise(env=os.environ): global early_log config = get_config(env) import talisker.logs talisker.logs.configure(config) _flush_early_logs() # now that logging is set up, initialise other modules # sentry first, so we can report any further errors in initialisation # TODO: add deferred logging, so we can set up sentry first thing import talisker.sentry if talisker.sentry.enabled: talisker.sentry.get_client() import talisker.statsd talisker.statsd.get_client() clear_contexts() return config
def initialise(env=os.environ): global early_log config = get_config(env) import talisker.logs talisker.logs.configure(config) flush_early_logs() # now that logging is set up, initialise other modules # sentry first, so we can report any further errors in initialisation # TODO: add deferred logging, so we can set up sentry first thing import talisker.sentry if talisker.sentry.enabled: talisker.sentry.get_client() import talisker.statsd talisker.statsd.get_client() clear_context() return config