예제 #1
0
def new():
    """Get a new furious context and add it to the registry."""

    new_context = Context()

    _local.get_local_context().registry.append(new_context)

    return new_context
예제 #2
0
    def test_persist_tree_after_tasks_inserted(self, mock_get_current_context):
        """
        Make sure a marker tree isn't(Raises exception)
        persisted after the current context's tasks have
        been inserted
        """
        from furious.context.context import Context
        from furious.marker_tree.identity_utils import leaf_persistence_id_from_group_id
        from furious.marker_tree.marker import Marker
        from furious.marker_tree.exceptions import NotSafeToSave

        a_context = Context(id="zebra")
        a_context._tasks_inserted = True
        mock_get_current_context.return_value = a_context
        root_marker = Marker(id="zebra")
        for x in xrange(3):
            root_marker.children.append(Marker(id=leaf_persistence_id_from_group_id(root_marker.id, x)))

        self.assertRaises(NotSafeToSave, root_marker.persist)
    def test_build_tree_from_context(self):
        from furious.context import _local
        from furious.context.context import Context
        from furious.marker_tree.marker import Marker
        from furious.marker_tree.graph_analysis import tree_graph_growth

        from furious.tests.marker_tree import dummy_success_callback

        context = Context()

        for arg in xrange(23):
            context.add(target=dummy_success_callback,
                        args=[arg])

        _local.get_local_context().registry.append(context)

        root_marker = Marker.make_marker_tree_for_context(context)

        root_marker.persist()
        # Plus one, because of the empty context.
        self.assertEqual(root_marker.count_nodes(), tree_graph_growth(23))
    def test_count_nodes(self):
        """Ensure Marker.count_nodes

        """
        from furious.context import _local
        from furious.context.context import Context
        from furious.marker_tree.marker import Marker

        from furious.tests.marker_tree import dummy_success_callback

        context = Context()

        context.add(target=dummy_success_callback,
                    args=[1])

        _local.get_local_context().registry.append(context)

        root_marker = Marker.make_marker_tree_for_context(context)

        root_marker.persist()
        # Plus one, because of the empty context.
        self.assertEqual(root_marker.count_nodes(), 2)
예제 #5
0
def new(batch_size=None, **options):
    """Get a new furious context and add it to the registry. If a batch size is
    specified, use an AutoContext which inserts tasks in batches as they are
    added to the context.
    """

    if batch_size:
        new_context = AutoContext(batch_size=batch_size, **options)
    else:
        new_context = Context(**options)

    _local.get_local_context().registry.append(new_context)

    return new_context
예제 #6
0
        return local_context._executing_async[-1]

    raise errors.NotInContextError("Not in an _ExecutionContext.")


def get_current_context():
    """Return a reference to the current Context object.
    """
    local_context = _local.get_local_context()

    if local_context.registry:
        return local_context.registry[-1]

    raise errors.NotInContextError("Not in a Context.")


def get_current_async_with_context():
    """Return a reference to the currently executing Async job object and it's
    triggering context. Return None for the async if not in an Async job and
    None for the context if the Async was not triggered within a context.
    """
    async = get_current_async()

    if not async:
        return None, None

    if not async.context_id:
        return async, None

    return async, Context.load(async.context_id)
예제 #7
0
    def __init__(self, batch_size=None, **options):
        """Setup this context in addition to accepting a batch_size."""

        Context.__init__(self, **options)

        self.batch_size = batch_size
예제 #8
0
    def __init__(self, batch_size=None, **options):
        """Setup this context in addition to accepting a batch_size."""

        Context.__init__(self, **options)

        self.batch_size = batch_size