def check_task_is_looping(
        self,
        state: State,
        inputs: Dict[str, Result] = None,
        upstream_states: Dict[Edge, State] = None,
        context: Dict[str, Any] = None,
        executor: "prefect.engine.executors.Executor" = None,
    ) -> State:
        """
        Checks to see if the task is in a `Looped` state and if so, rerun the pipeline with an incremeneted `loop_count`.

        Args:
            - state (State, optional): initial `State` to begin task run from;
                defaults to `Pending()`
            - inputs (Dict[str, Result], optional): a dictionary of inputs whose keys correspond
                to the task's `run()` arguments.
            - upstream_states (Dict[Edge, State]): a dictionary
                representing the states of any tasks upstream of this one. The keys of the
                dictionary should correspond to the edges leading to the task.
            - context (dict, optional): prefect Context to use for execution
            - executor (Executor, optional): executor to use when performing
                computation; defaults to the executor specified in your prefect configuration

        Returns:
            - `State` object representing the final post-run state of the Task
        """
        if state.is_looped():
            assert isinstance(state, Looped)  # mypy assert
            assert isinstance(context, dict)  # mypy assert
            msg = "Looping task (on loop index {})".format(state.loop_count)
            context.update(
                {
                    "task_loop_result": state.result,
                    "task_loop_count": state.loop_count + 1,
                }
            )
            context.update(task_run_version=prefect.context.get("task_run_version"))
            new_state = Pending(message=msg)
            raise RecursiveCall(
                self.run,
                self,
                new_state,
                upstream_states=upstream_states,
                context=context,
                executor=executor,
            )

        return state
Exemple #2
0
 def b_func(b=0):
     call_checkpoints.append(("b", b))
     if b > 5:
         return b
     b = a_func(b + 2)
     raise RecursiveCall(b_func, b + 2)
Exemple #3
0
 def a_func(a=0):
     call_checkpoints.append(("a", a))
     if a > 5:
         return a
     a = b_func(a + 1)
     raise RecursiveCall(a_func, (a + 1) * 2)
Exemple #4
0
 def utility_func(a):
     if a > 5:
         return a
     raise RecursiveCall(my_func, a + 2)
Exemple #5
0
 def my_func(calls=0):
     if calls > RECURSION_LIMIT + 10:
         return calls
     raise RecursiveCall(my_func, calls + 1)
Exemple #6
0
 def my_func(a=0):
     if a > 5:
         return a
     raise RecursiveCall(my_func, a + 2)