SameerMesiah97 commented on code in PR #63614:
URL: https://github.com/apache/airflow/pull/63614#discussion_r3142469606
##########
providers/microsoft/azure/src/airflow/providers/microsoft/azure/operators/synapse.py:
##########
@@ -255,30 +264,73 @@ def execute(self, context) -> None:
context["ti"].xcom_push(key="run_id", value=self.run_id)
if self.wait_for_termination:
- self.log.info("Waiting for pipeline run %s to terminate.",
self.run_id)
-
- if self.hook.wait_for_pipeline_run_status(
- run_id=self.run_id,
- expected_statuses=AzureSynapsePipelineRunStatus.SUCCEEDED,
- check_interval=self.check_interval,
- timeout=self.timeout,
- ):
- self.log.info("Pipeline run %s has completed successfully.",
self.run_id)
+ if not self.deferrable:
+ self.log.info("Waiting for pipeline run %s to terminate.",
self.run_id)
+ if self.hook.wait_for_pipeline_run_status(
+ run_id=self.run_id,
+ expected_statuses=AzureSynapsePipelineRunStatus.SUCCEEDED,
+ check_interval=self.check_interval,
+ timeout=self.timeout,
+ ):
+ self.log.info("Pipeline run %s has completed
successfully.", self.run_id)
+ else:
+ raise AzureSynapsePipelineRunException(
+ f"Pipeline run {self.run_id} has failed or has been
cancelled."
+ )
else:
- raise AzureSynapsePipelineRunException(
- f"Pipeline run {self.run_id} has failed or has been
cancelled."
+ end_time = time.time() + self.timeout
+
+ pipeline_run_status =
self.hook.get_pipeline_run_status(self.run_id)
+
+ if pipeline_run_status not in
AzureSynapsePipelineRunStatus.TERMINAL_STATUSES:
+ self.defer(
+ timeout=self.execution_timeout,
+ trigger=AzureSynapsePipelineTrigger(
+ azure_synapse_conn_id=self.azure_synapse_conn_id,
+
azure_synapse_workspace_dev_endpoint=self.azure_synapse_workspace_dev_endpoint,
+ run_id=self.run_id,
+ check_interval=self.check_interval,
+ end_time=end_time,
+ ),
+ method_name=self.execute_complete.__name__,
+ )
+
+ elif pipeline_run_status ==
AzureSynapsePipelineRunStatus.SUCCEEDED:
+ self.log.info("Pipeline run %s has completed
successfully.", self.run_id)
+
+ elif pipeline_run_status in
AzureSynapsePipelineRunStatus.FAILURE_STATES:
+ raise AzureSynapsePipelineRunException(
+ f"Pipeline run {self.run_id} has failed or has been
cancelled."
+ )
+ else:
+ if self.deferrable is True:
+ warnings.warn(
+ "Argument `wait_for_termination` is False and `deferrable`
is True, "
+ "hence `deferrable` parameter doesn't have any effect",
+ UserWarning,
+ stacklevel=2,
)
- def execute_complete(self, event: dict[str, str]) -> None:
+ def execute_complete(self, context: Context, event: dict[str, str] | None)
-> None:
"""
Return immediately - callback for when the trigger fires.
- Relies on trigger to throw an exception, otherwise it assumes
execution was successful.
+ The trigger communicates the terminal pipeline state through the event
payload.
"""
- if event:
- if event["status"] == "error":
- raise AirflowException(event["message"])
- self.log.info(event["message"])
+ if event is None:
+ raise AzureSynapsePipelineRunException("Trigger returned no
event.")
+
+ status = event.get("status")
+ message = event.get("message", "No message returned from trigger.")
+
+ if status == "success":
+ self.log.info(message)
+ return
+
+ if status == "error":
+ raise AzureSynapsePipelineRunException(message)
+
+ raise AzureSynapsePipelineRunException(f"Unexpected trigger event
received: {event}")
Review Comment:
No action needed here as this has been resolved in the trigger.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]