From 8d1b32e62ff2c1c67b75cdc4817585b76bb53edb Mon Sep 17 00:00:00 2001 From: Daniel Standish <15932138+dstandish@users.noreply.github.com> Date: Wed, 16 Nov 2022 22:57:22 -0800 Subject: [PATCH] Improve "sensor timeout" messaging It's been around a long, long time, but that doesn't make it any less confusing. I think it's time to do away with the "SNAP. Time is OUT" message, and replace it with something less cute / more clear / direct. --- airflow/sensors/base.py | 9 +++++++-- tests/sensors/test_external_task_sensor.py | 2 +- tests/sensors/test_timeout_sensor.py | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/airflow/sensors/base.py b/airflow/sensors/base.py index 0df1a5f4b7052..c64498f115c69 100644 --- a/airflow/sensors/base.py +++ b/airflow/sensors/base.py @@ -205,10 +205,15 @@ def run_duration() -> float: if run_duration() > self.timeout: # If sensor is in soft fail mode but times out raise AirflowSkipException. + message = ( + f"Sensor has timed out; run duration of {run_duration()} seconds exceeds " + f"the specified timeout of {self.timeout}." + ) + if self.soft_fail: - raise AirflowSkipException(f"Snap. Time is OUT. DAG id: {log_dag_id}") + raise AirflowSkipException(message) else: - raise AirflowSensorTimeout(f"Snap. Time is OUT. DAG id: {log_dag_id}") + raise AirflowSensorTimeout(message) if self.reschedule: next_poke_interval = self._get_next_poke_interval(started_at, run_duration, try_number) reschedule_date = timezone.utcnow() + timedelta(seconds=next_poke_interval) diff --git a/tests/sensors/test_external_task_sensor.py b/tests/sensors/test_external_task_sensor.py index 5754b35f13a31..80f538e8680ec 100644 --- a/tests/sensors/test_external_task_sensor.py +++ b/tests/sensors/test_external_task_sensor.py @@ -161,7 +161,7 @@ def test_raise_with_external_task_sensor_task_group_and_task_id(self): def test_external_task_group_not_exists_without_check_existence(self): self.add_time_sensor() self.add_dummy_task_group() - with pytest.raises(AirflowException, match=f"Snap. Time is OUT. DAG id: {TEST_DAG_ID}"): + with pytest.raises(AirflowException, match="Sensor has timed out"): op = ExternalTaskSensor( task_id="test_external_task_sensor_check", external_dag_id=TEST_DAG_ID, diff --git a/tests/sensors/test_timeout_sensor.py b/tests/sensors/test_timeout_sensor.py index 32102fbf4f647..3fcf66d199373 100644 --- a/tests/sensors/test_timeout_sensor.py +++ b/tests/sensors/test_timeout_sensor.py @@ -55,9 +55,9 @@ def execute(self, context: Context): started_at -= time_jump if (timezone.utcnow() - started_at).total_seconds() > self.timeout: if self.soft_fail: - raise AirflowSkipException("Snap. Time is OUT.") + raise AirflowSkipException("timeout") else: - raise AirflowSensorTimeout("Snap. Time is OUT.") + raise AirflowSensorTimeout("timeout") time.sleep(self.poke_interval) self.log.info("Success criteria met. Exiting.")