uranusjr commented on a change in pull request #16931:
URL: https://github.com/apache/airflow/pull/16931#discussion_r733641121



##########
File path: airflow/models/dag.py
##########
@@ -2706,6 +2707,7 @@ class DagModel(Base):
     # Earliest time at which this ``next_dagrun`` can be created.
     next_dagrun_create_after = Column(UtcDateTime)
 
+    timetable_description = Column(String, nullable=True)

Review comment:
       Maybe this can be better groupped under `schedule_interval` instead? 
That column is actually `timetable.summary` now but we just didn't bother to 
rename it.

##########
File path: airflow/timetables/base.py
##########
@@ -103,6 +103,12 @@ def logical_date(self) -> DateTime:
 class Timetable(Protocol):
     """Protocol that all Timetable classes are expected to implement."""
 
+    description: Optional[str] = None
+    """Describes the timetable interval,
+    eg. for  CronDataIntervalTimetable ``'30 21 * * 5'``,
+    description could be like ``'At 21:30, only on Friday'``, This is used in 
the webserver UI.
+    """

Review comment:
       ```suggestion
       """Human-readable description of the timetable.
   
       For example, this can produce something like ``'At 21:30, only on 
Friday'``
       from the cron expression ``'30 21 * * 5'``. This is used in the 
webserver UI.
       """
   ```
   
   Format this to be more in line with other docstrings on this class.

##########
File path: airflow/timetables/simple.py
##########
@@ -54,6 +54,9 @@ class NullTimetable(_TrivialTimetable):
     This corresponds to ``schedule_interval=None``.
     """
 
+    def __init__(self) -> None:
+        self.description = "Never, external triggers only"

Review comment:
       This can just be a class variable:
   
   ```python
   class NullTimetable(_TrivialTimetable):
       description = "Never, external triggers only"
   ```
   
   (Same goes for `OnceTimetable` below)

##########
File path: airflow/timetables/interval.py
##########
@@ -124,6 +125,19 @@ def __init__(self, cron: str, timezone: Timezone) -> None:
         self._expression = cron_presets.get(cron, cron)
         self._timezone = timezone
 
+        descriptor = ExpressionDescriptor(
+            expression=self._expression, casing_type=CasingTypeEnum.Sentence, 
use_24hour_time_format=True
+        )
+        try:
+            # checking for more than 5 parameters in Cron and avoiding 
evaluation for now,
+            # as Croniter has inconsistent evaluation with other libraries
+            if self._expression.count(" ") > 4:
+                raise FormatException()

Review comment:
       This could be fragile for inputs like `*/5 *  * * *` (notice the extra 
space between the second and third segment). It may be better to use `split()` 
here instead, or rely on `croniter`'s parser:
   
   ```pycon
   >>> from croniter import croniter
   >>> len(croniter('*/5 *  * * *').expanded)
   5
   >>> len(croniter('*/5 *  * * * 1').expanded)
   6
   ```




-- 
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]


Reply via email to