# 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.fromtypingimportAny,Dict,OptionalfrompendulumimportDateTimefromairflow.timetables.baseimportDagRunInfo,DataInterval,TimeRestriction,Timetableclass_TrivialTimetable(Timetable):"""Some code reuse for "trivial" timetables that has nothing complex."""periodic=Falsecan_run=False@classmethoddefdeserialize(cls,data:Dict[str,Any])->"Timetable":returncls()def__eq__(self,other:Any)->bool:"""As long as *other* is of the same type. This is only for testing purposes and should not be relied on otherwise. """ifnotisinstance(other,type(self)):returnNotImplementedreturnTruedefserialize(self)->Dict[str,Any]:return{}definfer_manual_data_interval(self,*,run_after:DateTime)->DataInterval:returnDataInterval.exact(run_after)
[docs]classNullTimetable(_TrivialTimetable):"""Timetable that never schedules anything. This corresponds to ``schedule_interval=None``. """
[docs]classOnceTimetable(_TrivialTimetable):"""Timetable that schedules the execution once as soon as possible. This corresponds to ``schedule_interval="@once"``. """
[docs]defnext_dagrun_info(self,*,last_automated_data_interval:Optional[DataInterval],restriction:TimeRestriction,)->Optional[DagRunInfo]:iflast_automated_data_intervalisnotNone:returnNone# Already run, no more scheduling.ifrestriction.earliestisNone:# No start date, won't run.returnNone# "@once" always schedule to the start_date determined by the DAG and# tasks, regardless of catchup or not. This has been the case since 1.10# and we're inheriting it. See AIRFLOW-1928.run_after=restriction.earliestifrestriction.latestisnotNoneandrun_after>restriction.latest:returnNonereturnDagRunInfo.exact(run_after)