Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass context to all callbacks calls instead of just passing it in the last call. #10340

Merged
merged 2 commits into from Jul 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/python/pants/reporting/streaming_workunit_handler.py
Expand Up @@ -45,13 +45,18 @@ def __init__(
self.report_interval = report_interval_seconds
self.callbacks = callbacks
self._thread_runner: Optional[_InnerHandler] = None
self._context = StreamingWorkunitContext(_scheduler=self.scheduler)
# TODO(10092) The max verbosity should be a per-client setting, rather than a global setting.
self.max_workunit_verbosity = max_workunit_verbosity

def start(self) -> None:
if self.callbacks:
self._thread_runner = _InnerHandler(
self.scheduler, self.callbacks, self.report_interval, self.max_workunit_verbosity
scheduler=self.scheduler,
context=self._context,
callbacks=self.callbacks,
report_interval=self.report_interval,
max_workunit_verbosity=self.max_workunit_verbosity,
)
self._thread_runner.start()

Expand All @@ -67,7 +72,7 @@ def end(self) -> None:
workunits=workunits["completed"],
started_workunits=workunits["started"],
finished=True,
context=StreamingWorkunitContext(_scheduler=self.scheduler),
context=self._context,
)

@contextmanager
Expand All @@ -86,12 +91,14 @@ class _InnerHandler(threading.Thread):
def __init__(
self,
scheduler: Any,
context: StreamingWorkunitContext,
callbacks: Iterable[Callable],
report_interval: float,
max_workunit_verbosity: LogLevel,
):
super().__init__(daemon=True)
self.scheduler = scheduler
self._context = context
self.stop_request = threading.Event()
self.report_interval = report_interval
self.callbacks = callbacks
Expand All @@ -105,6 +112,7 @@ def run(self):
workunits=workunits["completed"],
started_workunits=workunits["started"],
finished=False,
context=self._context,
)
self.stop_request.wait(timeout=self.report_interval)

Expand Down