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) and consumer.job_pool is not None: consumer.job_pool.job_completed(consumer, 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
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) and consumer.job_pool is not None: consumer.job_pool.job_completed(consumer, 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
def combine_references(self, other_ref): self.ref = combine_references(self.ref, other_ref)