TaskBuilder

dotflow.core.task.TaskBuilder

Import

You can import the Task class with:

from dotflow.core.task import TaskBuilder
Example

class dotflow.core.task.TaskBuilder

from uuid import uuid4

build = TaskBuilder(
    config=config
    workflow_id=uuid4()
)

Parameters:

Name Type Description Default
config Config

Configuration class.

required
workflow_id UUID

Workflow ID.

None
Source code in dotflow/core/task.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
class TaskBuilder:
    """
    Import:
        You can import the **Task** class with:

            from dotflow.core.task import TaskBuilder

    Example:
        `class` dotflow.core.task.TaskBuilder

            from uuid import uuid4

            build = TaskBuilder(
                config=config
                workflow_id=uuid4()
            )

    Args:
        config (Config): Configuration class.
        workflow_id (UUID): Workflow ID.
    """

    def __init__(
            self,
            config: Config,
            workflow_id: UUID = None
    ) -> None:
        self.queu: List[Callable] = []
        self.workflow_id = workflow_id
        self.config = config

    def add(
        self,
        step: Callable,
        callback: Callable = basic_callback,
        initial_context: Any = None,
    ) -> None:
        """
        Args:
            step (Callable):
                A argument that receives an object of the callable type,
                which is basically a function. You can see in this
                [example](https://dotflow-io.github.io/dotflow/nav/getting-started/#3-task-function).

            callback (Callable):
                Any callable object that receives **args** or **kwargs**,
                which is basically a function. You can see in this
                [example](https://dotflow-io.github.io/dotflow/nav/getting-started/#2-callback-function).

            initial_context (Context):
                The argument exists to include initial data in the execution
                of the workflow within the **function context**. This parameter
                can be accessed internally, for example: **initial_context**,
                to retrieve this information and manipulate it if necessary,
                according to the objective of the workflow.
        """
        if isinstance(step, list):
            for inside_step in step:
                self.add(
                    step=inside_step,
                    callback=callback,
                    initial_context=initial_context
                )
            return self

        self.queu.append(
            Task(
                task_id=len(self.queu),
                step=step,
                callback=Module(value=callback),
                initial_context=initial_context,
                workflow_id=self.workflow_id,
                config=self.config,
            )
        )

        return self

    def count(self) -> int:
        return len(self.queu)

    def clear(self) -> None:
        self.queu.clear()

    def reverse(self) -> None:
        self.queu.reverse()

add(step, callback=basic_callback, initial_context=None)

Parameters:

Name Type Description Default
step Callable

A argument that receives an object of the callable type, which is basically a function. You can see in this example.

required
callback Callable

Any callable object that receives args or kwargs, which is basically a function. You can see in this example.

basic_callback
initial_context Context

The argument exists to include initial data in the execution of the workflow within the function context. This parameter can be accessed internally, for example: initial_context, to retrieve this information and manipulate it if necessary, according to the objective of the workflow.

None
Source code in dotflow/core/task.py
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
def add(
    self,
    step: Callable,
    callback: Callable = basic_callback,
    initial_context: Any = None,
) -> None:
    """
    Args:
        step (Callable):
            A argument that receives an object of the callable type,
            which is basically a function. You can see in this
            [example](https://dotflow-io.github.io/dotflow/nav/getting-started/#3-task-function).

        callback (Callable):
            Any callable object that receives **args** or **kwargs**,
            which is basically a function. You can see in this
            [example](https://dotflow-io.github.io/dotflow/nav/getting-started/#2-callback-function).

        initial_context (Context):
            The argument exists to include initial data in the execution
            of the workflow within the **function context**. This parameter
            can be accessed internally, for example: **initial_context**,
            to retrieve this information and manipulate it if necessary,
            according to the objective of the workflow.
    """
    if isinstance(step, list):
        for inside_step in step:
            self.add(
                step=inside_step,
                callback=callback,
                initial_context=initial_context
            )
        return self

    self.queu.append(
        Task(
            task_id=len(self.queu),
            step=step,
            callback=Module(value=callback),
            initial_context=initial_context,
            workflow_id=self.workflow_id,
            config=self.config,
        )
    )

    return self

count()

Source code in dotflow/core/task.py
319
320
def count(self) -> int:
    return len(self.queu)

clear()

Source code in dotflow/core/task.py
322
323
def clear(self) -> None:
    self.queu.clear()

reverse()

Source code in dotflow/core/task.py
325
326
def reverse(self) -> None:
    self.queu.reverse()