Skip to content

capturegraph.procedures.nodes.automatic.structural #

Structural Procedures#

Structural procedures control the organization and execution order of other procedures. These define how workflows are composed, including sequential execution, parallel execution, dependencies, and optional steps.

Example
from capturegraph.procedures.nodes.action import CaptureImage, UserInputString
from capturegraph.procedures.nodes.automatic import ProcedureSequence, ProcedureSet
from capturegraph.procedures.nodes.filesystem import GetRootDirectory

def daily_capture():
    target = GetRootDirectory()
    session = target.new_session("daily")

    return ProcedureSequence(
        label="Daily Capture",
        procedures=[
            session.new_file("photo").save(CaptureImage(label="Photo")),
            session.new_file("notes").save(UserInputString(label="Notes")),
        ]
    )

ProcedureSequence #

Bases: Procedure[PVoid]

Executes a list of procedures in sequential order.

Each procedure in the list is executed one after another, waiting for completion before moving to the next. All procedures must return PVoid.

Attributes:

Name Type Description
procedures list[Procedure[PVoid]]

List of procedures to execute in order.

Example
return ProcedureSequence(
    label="Field Collection",
    procedures=[
        session.new_file("photo").save(CaptureImage(label="Photo")),
        session.new_file("location").save(CaptureLocation()),
    ]
)
Source code in capturegraph-lib/capturegraph/procedures/nodes/automatic/structural.py
@make_procedure
class ProcedureSequence(Procedure[PVoid]):
    """
    Executes a list of procedures in sequential order.

    Each procedure in the list is executed one after another, waiting for
    completion before moving to the next. All procedures must return `PVoid`.

    Attributes:
        procedures: List of procedures to execute in order.

    Example:
        ```python
        return ProcedureSequence(
            label="Field Collection",
            procedures=[
                session.new_file("photo").save(CaptureImage(label="Photo")),
                session.new_file("location").save(CaptureLocation()),
            ]
        )
        ```
    """

    procedures: list[Procedure[PVoid]]

ProcedureSet #

Bases: Procedure[PVoid]

Executes a list of procedures concurrently (in parallel).

All procedures in the set are started at the same time and can complete in any order. All procedures must return PVoid.

Attributes:

Name Type Description
procedures list[Procedure[PVoid]]

List of procedures to execute concurrently.

Example
# Save thumbnails in parallel
ProcedureSet(
    procedures=[
        set_thumbnail(target, thumbnail, skip_if_exists=True),
        set_thumbnail(session, thumbnail, skip_if_exists=True),
    ]
)
Source code in capturegraph-lib/capturegraph/procedures/nodes/automatic/structural.py
@make_procedure
class ProcedureSet(Procedure[PVoid]):
    """
    Executes a list of procedures concurrently (in parallel).

    All procedures in the set are started at the same time and can complete
    in any order. All procedures must return `PVoid`.

    Attributes:
        procedures: List of procedures to execute concurrently.

    Example:
        ```python
        # Save thumbnails in parallel
        ProcedureSet(
            procedures=[
                set_thumbnail(target, thumbnail, skip_if_exists=True),
                set_thumbnail(session, thumbnail, skip_if_exists=True),
            ]
        )
        ```
    """

    procedures: list[Procedure[PVoid]]

RequireProcedureCompleted #

Bases: Procedure[PVoid]

Ensures that a specific procedure has been completed successfully.

Acts as a checkpoint to verify that a required procedure has finished executing before allowing the workflow to continue. Useful for enforcing dependencies between procedures.

Attributes:

Name Type Description
procedure Procedure[PType]

The procedure that must be completed.

Source code in capturegraph-lib/capturegraph/procedures/nodes/automatic/structural.py
@make_procedure
class RequireProcedureCompleted(Procedure[PVoid]):
    """
    Ensures that a specific procedure has been completed successfully.

    Acts as a checkpoint to verify that a required procedure has finished
    executing before allowing the workflow to continue. Useful for enforcing
    dependencies between procedures.

    Attributes:
        procedure: The procedure that must be completed.
    """

    procedure: Procedure[PType]

OptionalProcedure #

Bases: Procedure[PVoid]

Marks a procedure as optional, allowing it to be skipped or fail gracefully.

The wrapped procedure can fail without causing the overall workflow to fail. Useful for non-critical actions like thumbnail generation.

Attributes:

Name Type Description
procedure Procedure[PVoid]

The procedure to make optional.

Example
# Make thumbnail save optional (won't block if it fails)
session.new_file("photo").save(photo),
set_thumbnail(session, thumbnail).make_optional(),
Source code in capturegraph-lib/capturegraph/procedures/nodes/automatic/structural.py
@make_procedure
class OptionalProcedure(Procedure[PVoid]):
    """
    Marks a procedure as optional, allowing it to be skipped or fail gracefully.

    The wrapped procedure can fail without causing the overall workflow to fail.
    Useful for non-critical actions like thumbnail generation.

    Attributes:
        procedure: The procedure to make optional.

    Example:
        ```python
        # Make thumbnail save optional (won't block if it fails)
        session.new_file("photo").save(photo),
        set_thumbnail(session, thumbnail).make_optional(),
        ```
    """

    procedure: Procedure[PVoid]