-
-
Notifications
You must be signed in to change notification settings - Fork 6
fix(TaskProducer): call close() on shutdown #718
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import atexit | ||
| from collections import deque | ||
| from collections.abc import Callable | ||
| from concurrent.futures import Future | ||
|
|
@@ -9,7 +10,7 @@ | |
|
|
||
| from taskbroker_client.constants import TASK_PRODUCER_MAX_PENDING_FUTURES | ||
| from taskbroker_client.metrics import MetricsBackend, NoOpMetricsBackend | ||
| from taskbroker_client.types import ProducerProtocol | ||
| from taskbroker_client.types import CloseableProducerProtocol | ||
|
|
||
| # This is global as TaskWorker needs to be able to call TaskProducer.collect_futures() | ||
| # without a reference to a task's specific instance of TaskProducer. | ||
|
|
@@ -39,17 +40,18 @@ class TaskProducer: | |
| def __init__( | ||
| self, | ||
| name: str, | ||
| producer_factory: Callable[[], ProducerProtocol], | ||
| producer_factory: Callable[[], CloseableProducerProtocol], | ||
| metrics_backend: MetricsBackend | None = None, | ||
| ) -> None: | ||
| self.name = name | ||
| self._producer_factory = producer_factory | ||
| self._inner_producer: ProducerProtocol | None = None | ||
| self._inner_producer: CloseableProducerProtocol | None = None | ||
| self.metrics = metrics_backend if metrics_backend is not None else NoOpMetricsBackend() | ||
|
|
||
| def _get(self) -> ProducerProtocol: | ||
| def _get(self) -> CloseableProducerProtocol: | ||
| if self._inner_producer is None: | ||
| self._inner_producer = self._producer_factory() | ||
| atexit.register(self._shutdown) | ||
|
sentry[bot] marked this conversation as resolved.
|
||
| return self._inner_producer | ||
|
|
||
| def track_future(self, future: ProducerFuture[BrokerValue[KafkaPayload]]) -> None: | ||
|
|
@@ -99,3 +101,7 @@ def produce( | |
| "or instantiate your producer with `use_simple_futures=False`." | ||
| ) | ||
| ) | ||
|
|
||
| def _shutdown(self) -> None: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The call to Suggested FixAdd a timeout to the Prompt for AI Agent
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if its unreachable we have bigger problems |
||
| if self._inner_producer is not None: | ||
| self._inner_producer.close().result() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a new type rather than updating
ProducerProtocolbecause that's used byTaskbrokerApp's producer factory, which returns aSingletonProducerin sentry, which has a different name for its shutdown method.