You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/03/21 21:00:29 UTC

[GitHub] [airflow] SamWheating commented on a change in pull request #22389: make operator's execution_timeout configurable

SamWheating commented on a change in pull request #22389:
URL: https://github.com/apache/airflow/pull/22389#discussion_r831538637



##########
File path: airflow/configuration.py
##########
@@ -608,6 +609,48 @@ def getjson(self, section, key, fallback=_UNSET, **kwargs) -> Union[dict, list,
         except JSONDecodeError as e:
             raise AirflowConfigException(f'Unable to parse [{section}] {key!r} as valid json') from e
 
+    def gettimedelta(self, section, key, fallback=None, **kwargs) -> Optional[datetime.timedelta]:
+        """
+        Gets the config value for the given section and key, and converts it into datetime.timedelta object.
+        If the key is missing or set to a non-positive value, then it is considered as `None`.
+
+        :param section: the section from the config
+        :param key: the key defined in the given section
+        :param fallback: fallback value when no config value is given, defaults to None
+        :raises AirflowConfigException: raised because ValueError or OverflowError
+        :return: datetime.timedelta(seconds=<config_value>) or None
+        """
+        val = self.get(section, key, fallback=fallback, **kwargs)
+
+        if val:
+            # the given value must be convertible to integer
+            try:
+                int_val = int(val)
+            except ValueError:
+                raise AirflowConfigException(
+                    f'Failed to convert value to int. Please check "{key}" key in "{section}" section. '
+                    f'Current value: "{val}".'
+                )
+
+            # the given value must be positive. Otherwise fallback value is returned.
+            if int_val <= 0:
+                raise AirflowConfigException(

Review comment:
       Is this error handled anywhere, or will this cause unhandled exceptions? The config reference entry says that:
   ```
   The missing and the non-positive values are considered as None, means that the operators are never timed out.
   ```
   
   Which suggests that a missing or non-positive value shouldn't raise an error and should instead just return None.
   
   




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org