Skip to content

Commit bb405f8

Browse files
authored
Merge pull request #598 from atlanhq/APP-5964
APP-5964 : Added a new param `workflow ID/name` to `client.workflow.monitor()`
2 parents b532ebe + 12e779b commit bb405f8

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

pyatlan/client/workflow.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -407,37 +407,48 @@ def update_owner(self, workflow_name: str, username: str) -> WorkflowResponse:
407407

408408
@validate_arguments(config=dict(arbitrary_types_allowed=True))
409409
def monitor(
410-
self, workflow_response: WorkflowResponse, logger: Optional[Logger] = None
410+
self,
411+
workflow_response: Optional[WorkflowResponse] = None,
412+
logger: Optional[Logger] = None,
413+
workflow_name: Optional[str] = None,
411414
) -> Optional[AtlanWorkflowPhase]:
412415
"""
413416
Monitor the status of the workflow's run.
414417
415418
:param workflow_response: The workflow_response returned from running the workflow
416419
:param logger: the logger to log status information
417-
(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
418422
:returns: the status at completion or None if the workflow wasn't run
419423
:raises ValidationError: If the provided `workflow_response`, `logger` is invalid
420424
:raises AtlanError: on any API communication issue
421425
"""
422-
if workflow_response.metadata and workflow_response.metadata.name:
423-
name = workflow_response.metadata.name
424-
status: Optional[AtlanWorkflowPhase] = None
425-
while status not in {
426-
AtlanWorkflowPhase.SUCCESS,
427-
AtlanWorkflowPhase.ERROR,
428-
AtlanWorkflowPhase.FAILED,
429-
}:
430-
sleep(MONITOR_SLEEP_SECONDS)
431-
if run_details := self._get_run_details(name):
432-
status = run_details.status
426+
name = workflow_name or (
427+
workflow_response.metadata.name
428+
if workflow_response and workflow_response.metadata
429+
else None
430+
)
431+
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
433446
if logger:
434447
logger.debug("Workflow status: %s", status)
435-
if logger:
436-
logger.info("Workflow completion status: %s", status)
437-
return status
448+
438449
if logger:
439-
logger.info("Skipping workflow monitoring — nothing to monitor.")
440-
return None
450+
logger.info("Workflow completion status: %s", status)
451+
return status
441452

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

tests/integration/test_workflow_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ def test_workflow_get_runs_and_stop(client: AtlanClient, workflow: WorkflowRespo
157157
workflow_status = client.workflow.monitor(workflow_response=workflow)
158158
assert workflow_status == AtlanWorkflowPhase.FAILED
159159

160+
# Test workflow monitoring by providing workflow name directly
161+
workflow_name = workflow.metadata.name
162+
workflow_status = client.workflow.monitor(workflow_name=workflow_name)
163+
assert workflow_status == AtlanWorkflowPhase.FAILED
164+
160165
# Test find run by id
161166
workflow_run = client.workflow.find_run_by_id(id=run.id)
162167
assert (

tests/unit/constants.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,6 @@
527527
],
528528
"instance of Logger expected",
529529
),
530-
([None, "test-logger"], "none is not an allowed value"),
531530
],
532531
"get_runs": [
533532
([[123], AtlanWorkflowPhase.RUNNING, 123, 456], "str type expected"),

0 commit comments

Comments
 (0)