Exemple #1
0
    def close(self):
        """Close the coordinator, leave the current group
        and reset local generation/memberId."""
        self._closing.set_result(None)
        if self._auto_commit_task:
            yield from self._auto_commit_task
            self._auto_commit_task = None

        if self.heartbeat_task:
            self.heartbeat_task.cancel()
            try:
                yield from self.heartbeat_task
            except asyncio.CancelledError:
                pass
            self.heartbeat_task = None

        if not (yield from self.coordinator_unknown()) and self.generation > 0:
            # this is a minimal effort attempt to leave the group. we do not
            # attempt any resending if the request fails or times out.
            request = LeaveGroupRequest(self.group_id, self.member_id)
            try:
                yield from self._send_req(self.coordinator_id,
                                          request,
                                          group=ConnectionGroup.COORDINATION)
            except Errors.KafkaError as err:
                log.error("LeaveGroup request failed: %s", err)
            else:
                log.info("LeaveGroup request succeeded")
Exemple #2
0
    def close(self):
        """Close the coordinator, leave the current group
        and reset local generation/memberId."""
        try:
            self._client.unschedule(self.heartbeat_task)
        except KeyError:
            pass
        if not self.coordinator_unknown() and self.generation > 0:
            # this is a minimal effort attempt to leave the group. we do not
            # attempt any resending if the request fails or times out.
            request = LeaveGroupRequest(self.group_id, self.member_id)
            future = self._client.send(self.coordinator_id, request)
            future.add_callback(self._handle_leave_group_response)
            future.add_errback(log.error, "LeaveGroup request failed: %s")
            self._client.poll(future=future)

        self.generation = OffsetCommitRequest.DEFAULT_GENERATION_ID
        self.member_id = JoinGroupRequest.UNKNOWN_MEMBER_ID
        self.rejoin_needed = True