Example #1
0
    def __init__(
            self, node, name, acked=False, init_state=None):
        self.loop = asyncio.get_event_loop()
        self.name = name
        self._producer = ProducerNode(name='{}_producer'.format(self.name))
        self._producer | list(node.initial_node_set)

        self.dag_members = node.dag_members
        self.acker = Acker()

        self._ensure_no_dup_name(self.dag_members)
        for member in self.dag_members:
            member.consecutor = self
Example #2
0
class Consecutor:
    def __init__(
            self, node, name, acked=False, init_state=None):
        self.loop = asyncio.get_event_loop()
        self.name = name
        self._producer = ProducerNode(name='{}_producer'.format(self.name))
        self._producer | list(node.initial_node_set)

        self.dag_members = node.dag_members
        self.acker = Acker()

        self._ensure_no_dup_name(self.dag_members)
        for member in self.dag_members:
            member.consecutor = self

    def _ensure_no_dup_name(self, member_set):
        counter = Counter()
        for member in member_set:
            counter.update({member.name: 1})
        dup_names = sorted(
            [name for (name, count) in counter.items() if count > 1])
        if dup_names:
            raise ValueError(
                (
                    '\n\nCan\'t create consecutor. The following duplicate\n'
                    'node names were detected: {}'
                ).format(dup_names)
            )

    def new_item(self, anchor, value):
        return Item(self.acker, anchor=anchor, value=value)

    def consume_iterable(self, iterable):
        self._producer.produce_from(iterable)
        self.loop.run_until_complete(
            asyncio.gather(*self._producer.get_starts()))

    def wait_till_processed(self, timeout_seconds=None):
        self.loop.run_until_complete(self._producer.complete())

    def draw_pdf(self, file_name):
        self._producer.draw_pdf(file_name)

    def __str__(self):
        return 'Consecutor({})'.format(self.name)

    def __repr__(self):
        return self.__str__()