Exemplo n.º 1
0
    def _publish_ref(self, global_id, ref, job, should_journal=True):
        
        if should_journal:
            job.add_reference(global_id, ref)
        
        # Record the name-to-concrete-reference mapping for this ref's name.
        try:
            current_ref = self.ref_for_output[global_id]
            combined_ref = combine_references(current_ref, ref)
            if not combined_ref:
                return
            if not combined_ref.is_consumable():
                del self.ref_for_output[global_id]
                return
            self.ref_for_output[global_id] = combined_ref
        except KeyError:
            if ref.is_consumable():
                self.ref_for_output[global_id] = ref
                current_ref = ref
            else:
                return

        # Notify any consumers that the ref is now available. N.B. After this,
        # the consumers are unsubscribed from this ref.
        try:
            consumers = self.consumers_for_output.pop(global_id)
            for consumer in consumers:
                if isinstance(consumer, Job):
                    consumer.completed(current_ref)
                else:
                    self.notify_task_of_reference(consumer, global_id, current_ref)
        except KeyError:
            pass
Exemplo n.º 2
0
    def _publish_ref(self,
                     global_id,
                     ref,
                     job=None,
                     should_journal=True,
                     task=None):

        if should_journal and job is not None:
            job.add_reference(global_id, ref)

        # Record the name-to-concrete-reference mapping for this ref's name.
        try:
            combined_ref = combine_references(self.ref_for_output[global_id],
                                              ref)
            if not combined_ref:
                return
            if not combined_ref.is_consumable():
                del self.ref_for_output[global_id]
                return
            self.ref_for_output[global_id] = combined_ref
        except KeyError:
            if ref.is_consumable():
                self.ref_for_output[global_id] = ref
            else:
                return

        current_ref = self.ref_for_output[global_id]

        if task is not None:
            self.task_for_output[global_id] = task

        # Notify any consumers that the ref is now available.
        # Contrary to how this was in earlier versions, tasks must unsubscribe themselves.
        # I always unsubscribe Jobs for simplicity, and because Jobs never need more than one callback.
        try:
            consumers = self.consumers_for_output[global_id]
            iter_consumers = consumers.copy()
            # Avoid problems with deletion from set during iteration
            for consumer in iter_consumers:
                if isinstance(consumer, Job):
                    consumer.completed(current_ref)
                    self.unregister_job_interest_for_output(
                        current_ref.id, consumer)
                else:
                    self.notify_task_of_reference(consumer, global_id,
                                                  current_ref)
        except KeyError:
            pass
Exemplo n.º 3
0
    def _publish_ref(self, global_id, ref, job=None, should_journal=True, task=None):
        
        if should_journal and job is not None:
            job.add_reference(global_id, ref)
        
        # Record the name-to-concrete-reference mapping for this ref's name.
        try:
            combined_ref = combine_references(self.ref_for_output[global_id], ref)
            if not combined_ref:
                return
            if not combined_ref.is_consumable():
                del self.ref_for_output[global_id]
                return
            self.ref_for_output[global_id] = combined_ref
        except KeyError:
            if ref.is_consumable():
                self.ref_for_output[global_id] = ref
            else:
                return

        current_ref = self.ref_for_output[global_id]

        if task is not None:
            self.task_for_output[global_id] = task

        # Notify any consumers that the ref is now available.
        # Contrary to how this was in earlier versions, tasks must unsubscribe themselves.
        # I always unsubscribe Jobs for simplicity, and because Jobs never need more than one callback.
        try:
            consumers = self.consumers_for_output[global_id]
            iter_consumers = consumers.copy()
            # Avoid problems with deletion from set during iteration
            for consumer in iter_consumers:
                if isinstance(consumer, Job):
                    consumer.completed(current_ref)
                    self.unregister_job_interest_for_output(current_ref.id, consumer)
                else:
                    self.notify_task_of_reference(consumer, global_id, current_ref)
        except KeyError:
            pass