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



##########
File path: airflow/timetables/base.py
##########
@@ -0,0 +1,133 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from typing import Iterator, NamedTuple, Optional
+
+from pendulum import DateTime
+
+from airflow.typing_compat import Protocol
+
+
+class DataInterval(NamedTuple):
+    """A data interval for a DagRun to operate over.
+
+    The represented interval is ``[start, end)``.
+    """
+
+    start: DateTime
+    end: DateTime
+
+
+class TimeRestriction(NamedTuple):
+    """Restriction on when a DAG can be scheduled for a run.
+
+    Specifically, the run must not be earlier than ``earliest``, nor later than
+    ``latest``. If ``catchup`` is *False*, the run must also not be earlier 
than
+    the current time, i.e. "missed" schedules are not backfilled.
+
+    These values are generally set on the DAG or task's ``start_date``,
+    ``end_date``, and ``catchup`` arguments.
+
+    Both ``earliest`` and ``latest`` are inclusive; a DAG run can happen 
exactly
+    at either point of time.
+    """
+
+    earliest: Optional[DateTime]
+    latest: Optional[DateTime]
+    catchup: bool
+
+
+class DagRunInfo(NamedTuple):
+    """Information to schedule a DagRun.
+
+    Instances of this will be returned by TimeTables when they are asked to
+    schedule a DagRun creation.
+    """
+
+    run_after: DateTime
+    """The earliest time this DagRun is created and its tasks scheduled."""
+
+    data_interval: DataInterval
+    """The data interval this DagRun to operate over, if applicable."""
+
+    @classmethod
+    def exact(cls, at: DateTime) -> "DagRunInfo":
+        """Represent a run on an exact time."""
+        return cls(run_after=at, data_interval=DataInterval(at, at))
+
+    @classmethod
+    def interval(cls, start: DateTime, end: DateTime) -> "DagRunInfo":
+        """Represent a run on a continuous schedule.
+
+        In such a schedule, each data interval starts right after the previous
+        one ends, and each run is scheduled right after the interval ends. This
+        applies to all schedules prior to AIP-39 except ``@once`` and ``None``.
+        """
+        return cls(run_after=end, data_interval=DataInterval(start, end))
+
+
+class TimeTable(Protocol):

Review comment:
       Protocol can have implementation as well (PEP 544 calls it default 
implementation), but adding the Protocol superclass makes Mypy complain if the 
protocol class is instantiated without subclassing. Another way is to make this 
an ABC like `BaseOperator` so instantiation fails at run-time (but that incurs 
more run-time penalty).




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to