Repository: apache/airflow
File: providers/microsoft/azure/src/airflow/providers/microsoft/azure/triggers/data_factory.py (Python)

Code before:
        """Make async connection to Azure Data Factory, polls for the pipeline run status."""
        executed_after_token_refresh = False
        try:
            async with AzureDataFactoryAsyncHook(
                azure_data_factory_conn_id=self.azure_data_factory_conn_id
            ) as hook:
                while True:
                    try:
                        pipeline_status = await hook.get_adf_pipeline_run_status(
                            run_id=self.run_id,
                            resource_group_name=self.resource_group_name,
                            factory_name=self.factory_name,
                        )
                        executed_after_token_refresh = False
                        event = self._build_trigger_event(pipeline_status)
                        if event:
                            yield event
                            return
                        await asyncio.sleep(self.poke_interval)
                    except ServiceRequestError:
                        # conn might expire during long running pipeline.
                        # If exception is caught, it tries to refresh connection once.
                        # If it still doesn't fix the issue,
                        # than the execute_after_token_refresh would still be False
                        # and an exception will be raised
                        if executed_after_token_refresh:
                            await hook.refresh_conn()
                            executed_after_token_refresh = False
                        else:
                            raise
        except Exception as e:
            yield TriggerEvent({"status": "error", "message": str(e)})


class AzureDataFactoryTrigger(BaseTrigger):
    """
    Trigger when the Azure data factory pipeline job finishes.

    When wait_for_termination is set to False, it triggers immediately with success status.

    :param run_id: Run id of a Azure data pipeline run job.
    :param azure_data_factory_conn_id: The connection identifier for connecting to Azure Data Factory.
    :param end_time: Time in seconds when triggers will timeout.
    :param resource_group_name: The resource group name.
    :param factory_name: The data factory name.
    :param wait_for_termination: Flag to wait on a pipeline run's termination.
    :param check_interval: Time in seconds to check on a pipeline run's status.
    """

    def __init__(
        self,

Review comment (suggestion):
Nit, but I would write it like this:

```
if not executed_after_token_refresh:
     raise
await hook.refresh_conn()
executed_after_token_refresh = False                            
```



Code after:
        """Make async connection to Azure Data Factory, polls for the pipeline run status."""
        executed_after_token_refresh = False
        try:
            async with AzureDataFactoryAsyncHook(
                azure_data_factory_conn_id=self.azure_data_factory_conn_id
            ) as hook:
                while True:
                    try:
                        pipeline_status = await hook.get_adf_pipeline_run_status(
                            run_id=self.run_id,
                            resource_group_name=self.resource_group_name,
                            factory_name=self.factory_name,
                        )
                        executed_after_token_refresh = False
                        event = self._build_trigger_event(pipeline_status)
                        if event:
                            yield event
                            return
                        await asyncio.sleep(self.poke_interval)
                    except ServiceRequestError:
                        # conn might expire during long running pipeline.
                        # If exception is caught, it tries to refresh connection once.
                        # If it still doesn't fix the issue,
                        # than the execute_after_token_refresh would still be False
                        # and an exception will be raised
                        if not executed_after_token_refresh:
                            raise
                        await hook.refresh_conn()
                        executed_after_token_refresh = False
        except Exception as e:
            yield TriggerEvent({"status": "error", "message": str(e)})


class AzureDataFactoryTrigger(BaseTrigger):
    """
    Trigger when the Azure data factory pipeline job finishes.

    When wait_for_termination is set to False, it triggers immediately with success status.

    :param run_id: Run id of a Azure data pipeline run job.
    :param azure_data_factory_conn_id: The connection identifier for connecting to Azure Data Factory.
    :param end_time: Time in seconds when triggers will timeout.
    :param resource_group_name: The resource group name.
    :param factory_name: The data factory name.
    :param wait_for_termination: Flag to wait on a pipeline run's termination.
    :param check_interval: Time in seconds to check on a pipeline run's status.
    """

    def __init__(
        self,
        run_id: str,