Example #1
0
    def run(self):
        """Main service entrypoint. Called via Thread.start() via PantsDaemon.run()."""

        if not (self._watchman and self._watchman.is_alive()):
            raise PantsService.ServiceError(
                'watchman is not running, bailing!')

        # Enable watchman for the build root.
        self._watchman.watch_project(self._build_root)

        futures = {}
        id_counter = 0
        subscriptions = list(self._handlers.values())

        # Setup subscriptions and begin the main event firing loop.
        for handler_name, event_data in self._watchman.subscribed(
                self._build_root, subscriptions):
            # On death, break from the loop and contextmgr to terminate callback threads.
            if self.is_killed: break

            if event_data:
                # As we receive events from watchman, submit them asynchronously to the executor.
                future = self._executor.submit(self.fire_callback,
                                               handler_name, event_data)
                futures[future] = handler_name

            # Process and log results for completed futures.
            for completed_future in [
                    _future for _future in futures if _future.done()
            ]:
                handler_name = futures.pop(completed_future)
                id_counter += 1

                try:
                    result = completed_future.result()
                except Exception:
                    result = traceback.format_exc()

                if result is not None:
                    # Truthy results or those that raise exceptions are treated as failures.
                    self._logger.warning(
                        'callback ID {} for {} failed: {}'.format(
                            id_counter, handler_name, result))
                else:
                    self._logger.debug(
                        'callback ID {} for {} succeeded'.format(
                            id_counter, handler_name))
Example #2
0
  def run(self):
    """Main service entrypoint. Called via Thread.start() via PantsDaemon.run()."""

    if not (self._watchman and self._watchman.is_alive()):
      raise PantsService.ServiceError('watchman is not running, bailing!')

    # Enable watchman for the build root.
    self._watchman.watch_project(self._build_root)

    subscriptions = list(self._handlers.values())

    # Setup subscriptions and begin the main event firing loop.
    for handler_name, event_data in self._watchman.subscribed(self._build_root, subscriptions):
      self._state.maybe_pause()
      if self._state.is_terminating:
        break

      if event_data:
        # As we receive events from watchman, trigger the relevant handlers.
        self.fire_callback(handler_name, event_data)
Example #3
0
    def run(self):
        """Main service entrypoint.

        Called via Thread.start() via PantsDaemon.run().
        """

        if not (self._watchman and self._watchman.is_alive()):
            raise PantsService.ServiceError("watchman is not running, bailing!")

        # Enable watchman for the build root and register our all_files handler.
        self._watchman.watch_project(self._build_root)

        # Setup subscriptions and begin the main event firing loop.
        for _, event_data in self._watchman.subscribed(self._build_root, [self._handler]):
            self._state.maybe_pause()
            if self._state.is_terminating:
                break
            if not event_data:
                continue

            self._handle_all_files_event(event_data)
            if not self._watchman_is_running.is_set():
                self._watchman_is_running.set()
Example #4
0
def test_run_abstract() -> None:
    with pytest.raises(TypeError):
        PantsService()  # type: ignore[abstract]
Example #5
0
 def test_run_abstract(self):
     with self.assertRaises(TypeError):
         PantsService()