37 lines
1.5 KiB
Python
Raw Normal View History

2024-06-26 15:45:06 -04:00
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from graphrag.callbacks.noop_workflow_callbacks import NoopWorkflowCallbacks
2024-06-26 15:45:06 -04:00
from graphrag_app.typing.pipeline import PipelineJobState
from graphrag_app.utils.pipeline import PipelineJob
2024-06-26 15:45:06 -04:00
class PipelineJobUpdater(NoopWorkflowCallbacks):
"""A callback that records pipeline updates."""
2024-06-26 15:45:06 -04:00
def __init__(self, pipeline_job: PipelineJob):
2024-06-26 15:45:06 -04:00
"""
This class defines a set of callback methods that can be used to log the progress of a pipeline job.
2024-06-26 15:45:06 -04:00
It inherits from the NoopWorkflowCallbacks class, which provides default implementations for all the callback methods.
Attributes:
pipeline_job (PipelineJob): The pipeline object associated with the job.
"""
self._pipeline_job = pipeline_job
def workflow_start(self, name: str, instance: object) -> None:
2024-06-26 15:45:06 -04:00
"""Execute this callback when a workflow starts."""
self._pipeline_job.status = PipelineJobState.RUNNING
2024-07-15 16:42:22 -07:00
self._pipeline_job.progress = f"Workflow {name} started."
2024-06-26 15:45:06 -04:00
def workflow_end(self, name: str, instance: object) -> None:
2024-06-26 15:45:06 -04:00
"""Execute this callback when a workflow ends."""
self._pipeline_job.completed_workflows.append(name)
self._pipeline_job.update_db()
2024-07-15 16:42:22 -07:00
self._pipeline_job.progress = f"Workflow {name} complete."
2024-06-26 15:45:06 -04:00
self._pipeline_job.percent_complete = (
self._pipeline_job.calculate_percent_complete()
)