예제 #1
0
    def persist(self):
        """
        Unless this is a root marker being saved before the Context
        it belongs to started, then
        a Marker must only be saved during the update_done stage
        just after it has been found to be done because
        more then one process may be checking the done status.
        If a value is changed, it must be done in an idempotent way,
        such that if a value is changed because of a child, other
        simultaneous processes would make the same change
        """
        from furious.context import get_current_context
        from furious.context import NotInContextError

        save_leaves = True
        is_root_marker = False
        # Infer if this is the root marker of a graph
        # or else just a node saving it's state.
        for child in self.children:
            if isinstance(child, Marker):
                # Indicates this is the root of a graph
                # and when a graph is saved, don't
                # save the leaves.
                is_root_marker = True
                save_leaves = False

        if save_leaves and not self._update_done_in_progress:
            raise NotSafeToSave('must only save during update_done'
                                ' or if this is a root marker of a graph before the context'
                                ' has inserted tasks')

        if is_root_marker:
            try:
                current_context = get_current_context()
                if current_context and current_context.id == self.id and \
                        current_context._tasks_inserted:
                    raise NotSafeToSave('cannot save after tasks have'
                                        ' been inserted')
            except NotInContextError:
                pass

        if hasattr(persistence_module, 'marker_persist') and \
                callable(persistence_module.marker_persist):
            persistence_module.marker_persist(self, save_leaves)
예제 #2
0
    def _get_context_id(self):
        """If this async is in a context set the context id."""

        from furious.context import get_current_context

        context_id = self._options.get('context_id')

        if context_id:
            return context_id

        try:
            context = get_current_context()
        except errors.NotInContextError:
            context = None
            self.update_options(context_id=None)

        if context:
            context_id = context.id
            self.update_options(context_id=context_id)

        return context_id
예제 #3
0
    def _get_context_id(self):
        """If this async is in a context set the context id."""

        from furious.context import get_current_context

        context_id = self._options.get('context_id')

        if context_id:
            return context_id

        try:
            context = get_current_context()
        except errors.NotInContextError:
            context = None
            self.update_options(context_id=None)

        if context:
            context_id = context.id
            self.update_options(context_id=context_id)

        return context_id
예제 #4
0
    def _persist_whole_graph(self):
        """
        For those times when you absolutely want to
        save every marker in the tree. It will overwrite any
        existing Markers. Children of this marker which are
        only ids of markers will not be saved.
        """
        from furious.context import get_current_context
        from furious.context import NotInContextError

        save_leaves = True
        if not self.is_leaf():
            try:
                current_context = get_current_context()
                if current_context and current_context.id == self.id and \
                        current_context._tasks_inserted:
                    raise NotSafeToSave('cannot save after tasks have'
                                        ' been inserted')
            except NotInContextError:
                pass
        if hasattr(persistence_module, 'marker_persist') and \
                callable(persistence_module.marker_persist):
            persistence_module.marker_persist(self, save_leaves)