Пример #1
0
    def resolve(self):
        pending_commands = self._build_pending_commands()

        num_commands = sum(len(v) for v in itervalues(pending_commands))
        # Don't bother with the pooling if we only need to do one operation on a single machine
        if num_commands == 1:
            db_num, (command,) = list(pending_commands.items())[0]
            self._commands = [command.resolve(self._cluster[db_num])]

        elif num_commands > 1:
            results = self.execute(self._cluster, pending_commands)

            for command in self._commands:
                result = results.get(command)

                if result:
                    for value in result:
                        if isinstance(value, Exception):
                            self._errors.append((command.get_name(), value))

                    # XXX: single path routing (implicit) doesnt return a list
                    if len(result) == 1:
                        result = result[0]

                change_resolution(command, result)

        self._resolved = True

        if not self._fail_silently and self._errors:
            raise CommandError(self._errors)
Пример #2
0
 def disconnect(self):
     """Disconnects all connections in cluster"""
     for connection in itervalues(self.hosts):
         connection.disconnect()