Add a new handler to the current batch.

def add(self, name, handler, group_by=None, aggregator=None):
        """Add a new handler to the current batch."""
        assert self.batch is not None, "No active batch, call start() first"

        items = self.batch.setdefault(name, collections.OrderedDict())
        if group_by is None:
            # None is special as it means no grouping. In this case we must store all
            # the different handlers and call them all.
            items.setdefault(group_by, []).append((None, handler))
        elif aggregator is not None:
            agg = items.get(group_by, [(None, None)])[0][0]
            items[group_by] = [(aggregator(agg), handler)]
        else:
            items[group_by] = [(None, handler)]