Esempio n. 1
0
    def test_grpc_server_handle_message_subscription(self, graphql_context):
        events = []
        test_subscriber = LocationStateSubscriber(events.append)
        location = next(
            iter(
                graphql_context.process_context._workspace.repository_locations  # pylint: disable=protected-access
            ))
        graphql_context.process_context._workspace.add_state_subscriber(  # pylint: disable=protected-access
            test_subscriber)
        location.client.shutdown_server()

        # Wait for event
        start_time = time.time()
        timeout = 60
        while not len(events) > 0:
            if time.time() - start_time > timeout:
                raise Exception(
                    "Timed out waiting for LocationStateChangeEvent")
            time.sleep(1)

        assert len(events) == 1
        assert isinstance(events[0], LocationStateChangeEvent)
        assert events[
            0].event_type == LocationStateChangeEventType.LOCATION_ERROR
        assert events[0].location_name == location.name
Esempio n. 2
0
    def __init__(
        self,
        instance: DagsterInstance,
        workspace: Workspace,
        version: Optional[str] = None,
        read_only: bool = False,
    ):

        check.inst_param(instance, "instance", DagsterInstance)
        check.inst_param(workspace, "workspace", Workspace)
        check.opt_str_param(version, "version")
        check.bool_param(read_only, "read_only")

        # lazy import for perf
        from rx.subjects import Subject

        self._instance = check.inst_param(instance, "instance",
                                          DagsterInstance)
        self._workspace = workspace

        self._location_state_events = Subject()
        self._location_state_subscriber = LocationStateSubscriber(
            self._location_state_events_handler)

        self.read_only = read_only
        self.version = version
        self.set_state_subscribers()
Esempio n. 3
0
    def __init__(
        self,
        instance: DagsterInstance,
        workspace_load_target: Optional[WorkspaceLoadTarget],
        version: str = "",
        read_only: bool = False,
        grpc_server_registry=None,
    ):
        self._stack = ExitStack()

        check.opt_str_param(version, "version")
        check.bool_param(read_only, "read_only")

        # lazy import for perf
        from rx.subjects import Subject

        self._instance = check.inst_param(instance, "instance",
                                          DagsterInstance)
        self._workspace_load_target = check.opt_inst_param(
            workspace_load_target, "workspace_load_target",
            WorkspaceLoadTarget)

        self._location_state_events = Subject()
        self._location_state_subscriber = LocationStateSubscriber(
            self._location_state_events_handler)

        self._read_only = read_only

        self._version = version

        # Guards changes to _location_dict, _location_error_dict, and _location_origin_dict
        self._lock = threading.Lock()

        # Only ever set up by main thread
        self._watch_thread_shutdown_events: Dict[str, threading.Event] = {}
        self._watch_threads: Dict[str, threading.Thread] = {}

        self._state_subscribers: List[LocationStateSubscriber] = []
        self.add_state_subscriber(self._location_state_subscriber)

        if grpc_server_registry:
            self._grpc_server_registry: GrpcServerRegistry = check.inst_param(
                grpc_server_registry, "grpc_server_registry",
                GrpcServerRegistry)
        else:
            self._grpc_server_registry = self._stack.enter_context(
                ProcessGrpcServerRegistry(
                    reload_interval=0,
                    heartbeat_ttl=DAGIT_GRPC_SERVER_HEARTBEAT_TTL,
                    startup_timeout=instance.
                    code_server_process_startup_timeout,
                ))

        self._location_entry_dict: Dict[
            str, WorkspaceLocationEntry] = OrderedDict()

        with self._lock:
            self._load_workspace()
Esempio n. 4
0
    def __init__(self, instance, workspace, version=None):
        # lazy import for perf
        from rx.subjects import Subject

        self._instance = check.inst_param(instance, "instance", DagsterInstance)
        self._workspace = workspace

        self._location_state_events = Subject()
        self._location_state_subscriber = LocationStateSubscriber(
            self._location_state_events_handler
        )

        self.version = version

        self._initialize_repository_locations()
Esempio n. 5
0
    def test_grpc_server_handle_message_subscription(self, graphql_context):
        events = []
        test_subscriber = LocationStateSubscriber(events.append)
        handle = next(
            iter(graphql_context._workspace.repository_location_handles  # pylint: disable=protected-access
                 ))
        handle.add_state_subscriber(test_subscriber)
        handle.client.shutdown_server()

        # Wait for event
        start_time = time.time()
        timeout = 30
        while not len(events) > 0:
            if time.time() - start_time > timeout:
                break
            time.sleep(1)

        assert len(events) == 1
        assert isinstance(events[0], LocationStateChangeEvent)
        assert events[
            0].event_type == LocationStateChangeEventType.LOCATION_ERROR
Esempio n. 6
0
    def __init__(self, instance, workspace, version=None):
        self._instance = check.inst_param(instance, "instance",
                                          DagsterInstance)
        self._workspace = workspace
        self._repository_locations = {}

        self._location_state_events = Subject()
        self._location_state_subscriber = LocationStateSubscriber(
            self._location_state_events_handler)

        for handle in self._workspace.repository_location_handles:
            check.invariant(
                self._repository_locations.get(handle.location_name) is None,
                'Cannot have multiple locations with the same name, got multiple "{name}"'
                .format(name=handle.location_name, ),
            )

            handle.add_state_subscriber(self._location_state_subscriber)
            self._repository_locations[
                handle.location_name] = RepositoryLocation.from_handle(handle)

        self.version = version