def define_publisher(module_path=None, **kwargs): module_path = module_path or publishers.__name__ module_labels = labels.make_labels(module_path, *PUBLISHER_LABEL_NAMES) setup_publisher( module_labels, parameters.define(module_path, make_publisher_params(**kwargs)), ) return module_labels
def define_client(module_path=None, **kwargs): module_path = module_path or clients.__name__ module_labels = labels.make_labels(module_path, *CLIENT_LABEL_NAMES) setup_client( module_labels, parameters.define(module_path, make_client_params(**kwargs)), ) return module_labels
def define_server(module_path=None, **kwargs): module_path = module_path or __package__ module_labels = labels.make_nested_labels(module_path, SERVER_LABEL_NAMES) setup_server( module_labels, parameters.define(module_path, make_server_params(**kwargs)), ) return module_labels
def define_console(module_path=None, **kwargs): module_path = module_path or __name__ module_labels = labels.make_labels(module_path, *CONSOLE_LABEL_NAMES) setup_console( module_labels, parameters.define(module_path, make_console_params(**kwargs)), ) return module_labels
def define_subscriber(module_path=None, **kwargs): module_path = module_path or subscribers.__name__ module_labels = labels.make_labels(module_path, *SUBSCRIBER_LABEL_NAMES) setup_subscriber( module_labels, parameters.define(module_path, make_subscriber_params(**kwargs)), ) return module_labels
def define_executor(module_path=None, **kwargs): """Define an executor under ``module_path``.""" module_path = module_path or executors.__name__ module_labels = labels.make_labels(module_path, *EXECUTOR_LABEL_NAMES) setup_executor( module_labels, parameters.define(module_path, make_executor_params(**kwargs)), ) return module_labels
def define_create_engine(module_path=None, **kwargs): """Define a database engine under ``module_path``.""" module_path = module_path or __package__ module_labels = labels.make_labels(module_path, *DATABASE_LABEL_NAMES) setup_create_engine( module_labels, parameters.define(module_path, make_create_engine_params(**kwargs)), ) return module_labels
def define_session(module_path=None, **kwargs): """Define a session object under ``module_path``.""" module_path = module_path or clients.__name__ module_labels = labels.make_labels(module_path, *SESSION_LABEL_NAMES) setup_session( module_labels, parameters.define( module_path, make_session_params(**kwargs), ), ) return module_labels
from g1.bases.assertions import ASSERT LOG = logging.getLogger(__name__) PARAMS = parameters.define( 'g1.operations', parameters.Namespace( repository=parameters.Parameter( Path('/var/lib/g1/operations'), 'path to the repository directory', convert=Path, validate=Path.is_absolute, format=str, ), application_group=parameters.Parameter( 'plumber', 'set application group', validate=bool, # Check not empty. ), zipapp_directory=parameters.Parameter( Path('/usr/local/bin'), 'path to install zipapp', convert=Path, validate=Path.is_absolute, format=str, ), ), ) REPO_LAYOUT_VERSION = 'v1'
from startup import startup from g1.apps import bases from g1.apps import parameters from g1.apps import utils from g1.bases import labels LABELS = labels.make_labels( __name__, 'f', 'x', ) PARAMS = parameters.define( __name__, parameters.Namespace(x=parameters.Parameter(0)), ) utils.depend_parameter_for(LABELS.x, PARAMS.x) def square(x): return x * x @startup def bind(x: LABELS.x) -> LABELS.f: x = x.get() return lambda: square(x)
from g1.asyncs.bases import tasks from g1.bases import labels from g1.http import clients LABELS = labels.make_nested_labels( __name__, ( ('session', g1.http.clients.parts.clusters.SESSION_LABEL_NAMES), ('stub', g1.http.clients.parts.clusters.STUB_LABEL_NAMES), ), ) g1.http.clients.parts.clusters.setup_session( LABELS.session, parameters.define( __name__ + '.session', g1.http.clients.parts.clusters.make_session_params(), ), ) g1.http.clients.parts.clusters.setup_stub( LABELS.stub, parameters.define( __name__ + '.stub', g1.http.clients.parts.clusters.make_stub_params(), ), ) utils.bind_label(LABELS.stub.stub, LABELS.session.stubs) utils.bind_label(g1.threads.parts.define_executor().executor, LABELS.session.executor)
from startup import startup from g1.apps import bases from g1.apps import parameters from g1.bases import labels from .. import scripts # pylint: disable=relative-beyond-top-level LABELS = labels.make_labels( 'g1.scripts', 'setup', ) PARAMS = parameters.define( 'g1.scripts', parameters.Namespace( dry_run=parameters.Parameter(False, 'whether to dry-run commands'), ), ) @startup def setup( exit_stack: bases.LABELS.exit_stack, _: parameters.LABELS.parameters, ) -> LABELS.setup: exit_stack.enter_context(scripts.doing_dry_run(PARAMS.dry_run.get()))
from .. import agents # pylint: disable=relative-beyond-top-level LABELS = labels.make_labels( agents.__name__, # supervise_agents. 'supervise_agents', 'agent_queue', 'graceful_exit', 'grace_period', # shutdown_agents. 'shutdown_queue', ) PARAMS = parameters.define( agents.__name__, parameters.Namespace(grace_period=parameters.Parameter(4, type=(int, float), unit='seconds'), ), ) startup.set(LABELS.agent_queue, tasks.CompletionQueue()) startup.set(LABELS.graceful_exit, locks.Event()) startup.set(LABELS.shutdown_queue, queues.Queue()) utils.depend_parameter_for(LABELS.grace_period, PARAMS.grace_period) utils.define_binder( agents.supervise_agents, LABELS.supervise_agents, { 'agent_queue': LABELS.agent_queue, 'graceful_exit': LABELS.graceful_exit,
from g1.bases.assertions import ASSERT LOG = logging.getLogger(__name__) PARAMS = parameters.define( 'g1.containers', parameters.Namespace( repository=parameters.Parameter( Path('/var/lib/g1/containers'), 'path to the repository directory', convert=Path, validate=Path.is_absolute, format=str, ), application_group=parameters.Parameter( 'plumber', 'set application group', validate=bool, # Check not empty. ), xar_runner_script_directory=parameters.Parameter( Path('/usr/local/bin'), 'path to the xar runner script directory', convert=Path, validate=Path.is_absolute, format=str, ), ), ) REPO_LAYOUT_VERSION = 'v1'
from . import executors from . import tasks LOG = logging.getLogger(__name__) PARAMS = parameters.define( __name__, parameters.Namespace( 'configure monitor', period=parameters.Parameter( 10, type=(int, float), unit='seconds', ), executor_queue_threshold=parameters.Parameter( # If you have enough executor threads, this queue should # never accumulate backlog. 1, validate=(0).__le__, ), num_tasks_threshold=parameters.Parameter( 200, validate=(0).__le__, ), ), ) PARAMS_LABEL = labels.Label(__name__, 'params') async def monitor(
from g1.apps import utils from g1.bases import labels from g1.threads import futures import g1.threads.parts LABELS = labels.make_labels( __name__, 'executor_params', 'executor', ) utils.depend_parameter_for( LABELS.executor_params, parameters.define( __name__, g1.threads.parts.make_executor_params(), ), ) utils.define_maker( g1.threads.parts.make_executor, { 'params': LABELS.executor_params, 'return': LABELS.executor, }, ) def square(x): duration = random.uniform(0, 4) time.sleep(duration)