def commit(self):
        """Commit a batch."""
        assert self.batch is not None, "No active batch, call start() first"

        logger.debug("Comitting batch from %d sources...", len(self.batch))

        # Determine item priority.
        by_priority = []
        for name in self.batch.keys():
            priority = self.priorities.get(name, self.default_priority)
            by_priority.append((priority, name))

        for priority, name in sorted(by_priority, key=lambda key: key[0]):
            logger.debug("Processing items from '%s' (priority=%d)...", name, priority)
            items = self.batch[name]
            for handlers in items.values():
                for agg, handler in handlers:
                    try:
                        if agg is None:
                            handler()
                        else:
                            handler(agg)
                    except Exception as error:
                        # Log errors and proceed to evaluate the next handler.
                        logger.exception("Error while invoking handler.")

        self.batch = None

        logger.debug("Batch committed.")
Commit a batch.