Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve "sensor timeout" messaging #27733

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions airflow/sensors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/sensors/test_external_task_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions tests/sensors/test_timeout_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down