Skip to content

task_context

TaskContext

Bases: WorkflowTaskNode

Gather a valid AYON task context.

Source code in client/ayon_workflow/plugins/workflow/essentials/task_context.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class TaskContext(WorkflowTaskNode):
    """Gather a valid AYON task context."""

    version = "0.0.1"
    inputs = [
        InputAttribute(
            name="project_name",
            description="The project name",
        ),
        InputAttribute(
            name="task_id",
            description="An optional task id.",
        ),
        InputAttribute(
            name="task_path",
            description="An optional task path.",
        ),
        InputAttribute(
            name="ensure_exists",
            description="Assert context existence.",
        ),
    ]
    outputs = [
        OutputAttribute(
            name="task_context",
            description="The task context as a TaskItem.",
        )
    ]

    def execute(
        self,
        project_name: str,
        task_id: Optional[str] = None,
        task_path: Optional[str] = None,
        ensure_exists: Optional[bool] = True,
    ) -> TaskItem:
        if not task_id and (not task_path):
            raise ValueError("Either task_id or task_path must be provided.")

        if task_id:
            task_dict = ayon_api.get_task_by_id(project_name, task_id) or {}
            task_name = task_dict.get("name", "unknown")
            folder_path = None
            folder_id = task_dict.get("folderId", "unknown")
        else:
            folder_path, task_name = task_path.rsplit("/", 1)
            folder_id = None

        return Context().execute(
            project_name,
            folder_id=folder_id,
            folder_path=folder_path,
            task_name=task_name,
            ensure_exists=ensure_exists,
        )