Ejemplo n.º 1
0
def grpc_command(port=None, socket=None, host='localhost', **kwargs):
    if seven.IS_WINDOWS and port is None:
        raise click.UsageError(
            'You must pass a valid --port/-p on Windows: --socket/-f not supported.'
        )
    if not (port or socket and not (port and socket)):
        raise click.UsageError(
            'You must pass one and only one of --port/-p or --socket/-f.')

    loadable_target_origin = None
    if any(kwargs[key] for key in
           ['attribute', 'working_directory', 'module_name', 'python_file']):
        loadable_target_origin = LoadableTargetOrigin(
            executable_path=sys.executable,
            attribute=kwargs['attribute'],
            working_directory=kwargs['working_directory'],
            module_name=kwargs['module_name'],
            python_file=kwargs['python_file'],
        )

    server = DagsterGrpcServer(port=port,
                               socket=socket,
                               host=host,
                               loadable_target_origin=loadable_target_origin)

    server.serve()
Ejemplo n.º 2
0
def grpc_command(
    port=None,
    socket=None,
    host="localhost",
    max_workers=None,
    heartbeat=False,
    heartbeat_timeout=30,
    lazy_load_user_code=False,
    ipc_output_file=None,
    fixed_server_id=None,
    override_system_timezone=None,
    **kwargs,
):
    if seven.IS_WINDOWS and port is None:
        raise click.UsageError(
            "You must pass a valid --port/-p on Windows: --socket/-s not supported."
        )
    if not (port or socket and not (port and socket)):
        raise click.UsageError("You must pass one and only one of --port/-p or --socket/-s.")

    loadable_target_origin = None
    if any(
        kwargs[key]
        for key in [
            "attribute",
            "working_directory",
            "module_name",
            "package_name",
            "python_file",
            "empty_working_directory",
        ]
    ):
        loadable_target_origin = LoadableTargetOrigin(
            executable_path=sys.executable,
            attribute=kwargs["attribute"],
            working_directory=get_working_directory_from_kwargs(kwargs),
            module_name=kwargs["module_name"],
            python_file=kwargs["python_file"],
            package_name=kwargs["package_name"],
        )

    with (
        mock_system_timezone(override_system_timezone)
        if override_system_timezone
        else nullcontext()
    ):
        server = DagsterGrpcServer(
            port=port,
            socket=socket,
            host=host,
            loadable_target_origin=loadable_target_origin,
            max_workers=max_workers,
            heartbeat=heartbeat,
            heartbeat_timeout=heartbeat_timeout,
            lazy_load_user_code=lazy_load_user_code,
            ipc_output_file=ipc_output_file,
            fixed_server_id=fixed_server_id,
        )

        server.serve()
Ejemplo n.º 3
0
def grpc_command(port=None, socket=None, host='localhost'):
    if seven.IS_WINDOWS and port is None:
        raise click.UsageError(
            'You must pass a valid --port/-p on Windows: --socket/-f not supported.'
        )
    if not (port or socket and not (port and socket)):
        raise click.UsageError(
            'You must pass one and only one of --port/-p or --socket/-f.')

    server = DagsterGrpcServer(port=port, socket=socket, host=host)
    server.serve()
Ejemplo n.º 4
0
def test_server_port_and_socket():
    with safe_tempfile_path() as skt:
        with pytest.raises(
                check.CheckError,
                match=re.escape(
                    "You must pass one and only one of `port` or `socket`."),
        ):
            DagsterGrpcServer(socket=skt, port=find_free_port())
Ejemplo n.º 5
0
def grpc_command(port=None,
                 socket=None,
                 host="localhost",
                 max_workers=1,
                 heartbeat=False,
                 heartbeat_timeout=30,
                 lazy_load_user_code=False,
                 **kwargs):
    if seven.IS_WINDOWS and port is None:
        raise click.UsageError(
            "You must pass a valid --port/-p on Windows: --socket/-f not supported."
        )
    if not (port or socket and not (port and socket)):
        raise click.UsageError(
            "You must pass one and only one of --port/-p or --socket/-f.")

    loadable_target_origin = None
    if any(kwargs[key] for key in
           ["attribute", "working_directory", "module_name", "python_file"]):
        loadable_target_origin = LoadableTargetOrigin(
            executable_path=sys.executable,
            attribute=kwargs["attribute"],
            working_directory=get_working_directory_from_kwargs(kwargs),
            module_name=kwargs["module_name"],
            python_file=kwargs["python_file"],
        )

    server = DagsterGrpcServer(
        port=port,
        socket=socket,
        host=host,
        loadable_target_origin=loadable_target_origin,
        max_workers=max_workers,
        heartbeat=heartbeat,
        heartbeat_timeout=heartbeat_timeout,
        lazy_load_user_code=lazy_load_user_code,
    )

    server.serve()
Ejemplo n.º 6
0
def test_server_socket_on_windows():
    with safe_tempfile_path() as skt:
        with pytest.raises(check.CheckError,
                           match=re.escape("`socket` not supported")):
            DagsterGrpcServer(socket=skt)
Ejemplo n.º 7
0
 def _runnable():
     server = DagsterGrpcServer(**kwargs)
     server.serve()
Ejemplo n.º 8
0
def grpc_command(
    port=None,
    socket=None,
    host=None,
    max_workers=None,
    heartbeat=False,
    heartbeat_timeout=30,
    lazy_load_user_code=False,
    ipc_output_file=None,
    fixed_server_id=None,
    override_system_timezone=None,
    log_level="INFO",
    use_python_environment_entry_point=False,
    container_context=None,
    **kwargs,
):
    if seven.IS_WINDOWS and port is None:
        raise click.UsageError(
            "You must pass a valid --port/-p on Windows: --socket/-s not supported."
        )
    if not (port or socket and not (port and socket)):
        raise click.UsageError(
            "You must pass one and only one of --port/-p or --socket/-s.")

    configure_loggers(log_level=coerce_valid_log_level(log_level))
    logger = logging.getLogger("dagster.code_server")

    loadable_target_origin = None
    if any(kwargs[key] for key in [
            "attribute",
            "working_directory",
            "module_name",
            "package_name",
            "python_file",
            "empty_working_directory",
    ]):
        loadable_target_origin = LoadableTargetOrigin(
            executable_path=sys.executable,
            attribute=kwargs["attribute"],
            working_directory=(None if kwargs.get("empty_working_directory")
                               else get_working_directory_from_kwargs(kwargs)),
            module_name=kwargs["module_name"],
            python_file=kwargs["python_file"],
            package_name=kwargs["package_name"],
        )

    with (mock_system_timezone(override_system_timezone)
          if override_system_timezone else nullcontext()):
        server = DagsterGrpcServer(
            port=port,
            socket=socket,
            host=host,
            loadable_target_origin=loadable_target_origin,
            max_workers=max_workers,
            heartbeat=heartbeat,
            heartbeat_timeout=heartbeat_timeout,
            lazy_load_user_code=lazy_load_user_code,
            ipc_output_file=ipc_output_file,
            fixed_server_id=fixed_server_id,
            entry_point=(get_python_environment_entry_point(sys.executable)
                         if use_python_environment_entry_point else
                         DEFAULT_DAGSTER_ENTRY_POINT),
            container_context=json.loads(container_context)
            if container_context != None else None,
        )

        code_desc = " "
        if loadable_target_origin:
            if loadable_target_origin.python_file:
                code_desc = f" for file {loadable_target_origin.python_file} "
            elif loadable_target_origin.package_name:
                code_desc = f" for package {loadable_target_origin.package_name} "
            elif loadable_target_origin.module_name:
                code_desc = f" for module {loadable_target_origin.module_name} "

        server_desc = (
            f"Dagster code server{code_desc}on port {port} in process {os.getpid()}"
            if port else
            f"Dagster code server{code_desc}in process {os.getpid()}")

        logger.info("Started {server_desc}".format(server_desc=server_desc))

        try:
            server.serve()
        finally:
            logger.info(
                "Shutting down {server_desc}".format(server_desc=server_desc))