OpenMetadata/ingestion/src/metadata/utils/workflow_helper.py
Mayur Singal 1386b43607
Fix #6141: Ingestion Pipeline Status Updates (#8216)
* Fix #6141: Ingestion Pipeline Status Updates

* List Pipeline Status API & Improvements

* Rename State field to PipelineState in UI

* Convert Pipeline Status array to single object

* fix braking UI

* Rebase Fixes

* Profiler, TestStuite & DataInsigts Pipeline

* py_format

* fix logs page not loading
add pipelineStatus endpoint

* fix recent run changes

* Fix Tests

* address review comments for ui

* fix failing checks

* fix unit tests

* fix cypress test

* remove loader test as not using it

* wait for API when we click on the tab

* fix cypress waitFor api

* fix failed cypress tests

Co-authored-by: Chirag Madlani <12962843+chirag-madlani@users.noreply.github.com>
2022-11-03 14:37:26 +05:30

59 lines
2.1 KiB
Python

# Copyright 2021 Collate
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Modules contains helper methods for different workflows
"""
import uuid
from datetime import datetime
from metadata.generated.schema.entity.services.ingestionPipelines.ingestionPipeline import (
PipelineState,
PipelineStatus,
)
from metadata.ingestion.ometa.ometa_api import OpenMetadata
def set_ingestion_pipeline_status(
state: PipelineState,
ingestion_pipeline_fqn: str,
pipeline_run_id: str,
metadata: OpenMetadata,
) -> str:
"""
Method to set the pipeline status of current ingestion pipeline
"""
if ingestion_pipeline_fqn:
# if ingestion pipeline fqn is not set then setting pipeline status is avoided
pipeline_status: PipelineStatus = None
if state in (PipelineState.queued, PipelineState.running):
pipeline_run_id = pipeline_run_id or str(uuid.uuid4())
pipeline_status = PipelineStatus(
runId=pipeline_run_id,
pipelineState=state,
startDate=datetime.now().timestamp() * 1000,
timestamp=datetime.now().timestamp() * 1000,
)
elif pipeline_run_id:
pipeline_status = metadata.get_pipeline_status(
ingestion_pipeline_fqn, pipeline_run_id
)
# if workflow is ended then update the end date in status
pipeline_status.endDate = datetime.now().timestamp() * 1000
pipeline_status.pipelineState = state
metadata.create_or_update_pipeline_status(
ingestion_pipeline_fqn, pipeline_status
)
return pipeline_run_id
return None