pateash commented on a change in pull request #16931:
URL: https://github.com/apache/airflow/pull/16931#discussion_r670949174
##########
File path: airflow/models/dag.py
##########
@@ -2404,6 +2404,20 @@ def __repr__(self):
def timezone(self):
return settings.TIMEZONE
+ @property
+ def timetable(self) -> Timetable:
+ interval = self.schedule_interval
+ if interval is None:
+ return NullTimetable()
+ if interval == "@once":
+ return OnceTimetable()
+ if isinstance(interval, (timedelta, relativedelta)):
+ return DeltaDataIntervalTimetable(interval)
+ if isinstance(interval, str):
+ return CronDataIntervalTimetable(interval, self.timezone)
+ type_name = type(interval).__name__
+ raise TypeError(f"{type_name} is not a valid DAG.schedule_interval.")
Review comment:
Yeah, thought about the same,
but I am also not sure, how to do it,
we can create a base class like DagBase which will have the common
properties, but I think it's a overkill but a better approach so applying this.
```python
class DagBase(Base):
"""A Base Class for Dag"""
@cached_property
def timetable(self) -> Timetable:
interval = self.schedule_interval
if interval is None:
return NullTimetable()
if interval == "@once":
return OnceTimetable()
if isinstance(interval, (timedelta, relativedelta)):
return DeltaDataIntervalTimetable(interval)
if isinstance(interval, str):
return CronDataIntervalTimetable(interval, self.timezone)
type_name = type(interval).__name__
raise TypeError(f"{type_name} is not a valid DAG.schedule_interval.")
```
--
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]