Skip to content

Commit 12e779b

Browse files
committed
[change] Used guard clause (early return) + simplified workflow name extraction
1 parent e2e0b4e commit 12e779b

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

pyatlan/client/workflow.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
ReRunRequest,
3030
ScheduleQueriesSearchRequest,
3131
Workflow,
32-
WorkflowMetadata,
3332
WorkflowResponse,
3433
WorkflowRunResponse,
3534
WorkflowSchedule,
@@ -417,37 +416,39 @@ def monitor(
417416
Monitor the status of the workflow's run.
418417
419418
:param workflow_response: The workflow_response returned from running the workflow
420-
:param workflow_name: name of the workflow to be monitored
421419
:param logger: the logger to log status information
422-
(logging.INFO for summary info. logging:DEBUG for detail info)
420+
(logging.INFO for summary info. logging.DEBUG for detail info)
421+
:param workflow_name: name of the workflow to be monitored
423422
:returns: the status at completion or None if the workflow wasn't run
424423
:raises ValidationError: If the provided `workflow_response`, `logger` is invalid
425424
:raises AtlanError: on any API communication issue
426425
"""
427-
if workflow_name and not workflow_response:
428-
workflow_response = WorkflowResponse(
429-
metadata=WorkflowMetadata(name=workflow_name)
430-
)
426+
name = workflow_name or (
427+
workflow_response.metadata.name
428+
if workflow_response and workflow_response.metadata
429+
else None
430+
)
431431

432-
if workflow_response.metadata and workflow_response.metadata.name: # type: ignore
433-
name = workflow_response.metadata.name # type: ignore
434-
status: Optional[AtlanWorkflowPhase] = None
435-
while status not in {
436-
AtlanWorkflowPhase.SUCCESS,
437-
AtlanWorkflowPhase.ERROR,
438-
AtlanWorkflowPhase.FAILED,
439-
}:
440-
sleep(MONITOR_SLEEP_SECONDS)
441-
if run_details := self._get_run_details(name):
442-
status = run_details.status
432+
if not name:
433+
if logger:
434+
logger.info("Skipping workflow monitoring — nothing to monitor.")
435+
return None
436+
437+
status: Optional[AtlanWorkflowPhase] = None
438+
while status not in {
439+
AtlanWorkflowPhase.SUCCESS,
440+
AtlanWorkflowPhase.ERROR,
441+
AtlanWorkflowPhase.FAILED,
442+
}:
443+
sleep(MONITOR_SLEEP_SECONDS)
444+
if run_details := self._get_run_details(name):
445+
status = run_details.status
443446
if logger:
444447
logger.debug("Workflow status: %s", status)
445-
if logger:
446-
logger.info("Workflow completion status: %s", status)
447-
return status
448+
448449
if logger:
449-
logger.info("Skipping workflow monitoring — nothing to monitor.")
450-
return None
450+
logger.info("Workflow completion status: %s", status)
451+
return status
451452

452453
def _get_run_details(self, name: str) -> Optional[WorkflowSearchResult]:
453454
return self._find_latest_run(workflow_name=name)

0 commit comments

Comments
 (0)