예제 #1
0
 def done(task: Future) -> None:
     try:
         if fut.done():  # pragma: nocover
             return
         if task.exception():
             fut.set_exception(task.exception())
         else:  # pragma: nocover
             fut.set_result(None)
     finally:
         self._got_result = True
예제 #2
0
def published_callback(topic: str, start_time: float, fut: Future) -> None:
    # Record the metrics
    finish_time = time.time()
    exception = fut.exception()
    if exception:
        error = str(exception.__class__.__name__)
        PUBLISHED_MESSAGES.labels(stream_id=topic, partition=-1,
                                  error=error).inc()
    else:
        metadata = fut.result()
        PUBLISHED_MESSAGES.labels(stream_id=topic,
                                  partition=metadata.partition,
                                  error=NOERROR).inc()
        PRODUCER_TOPIC_OFFSET.labels(stream_id=topic,
                                     partition=metadata.partition).set(
                                         metadata.offset)
        PUBLISHED_MESSAGES_TIME.labels(stream_id=topic).observe(finish_time -
                                                                start_time)