Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/airflow/ti_deps/deps/runnable_exec_date_dep.py: 53%
17 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
1#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18from __future__ import annotations
20from airflow.ti_deps.deps.base_ti_dep import BaseTIDep
21from airflow.utils import timezone
22from airflow.utils.session import provide_session
25class RunnableExecDateDep(BaseTIDep):
26 """Determines whether a task's execution date is valid."""
28 NAME = "Execution Date"
29 IGNORABLE = True
31 @provide_session
32 def _get_dep_statuses(self, ti, session, dep_context):
33 cur_date = timezone.utcnow()
35 # don't consider runs that are executed in the future unless
36 # specified by config and schedule_interval is None
37 logical_date = ti.get_dagrun(session).execution_date
38 if logical_date > cur_date and not ti.task.dag.allow_future_exec_dates:
39 yield self._failing_status(
40 reason=(
41 f"Execution date {logical_date.isoformat()} is in the future "
42 f"(the current date is {cur_date.isoformat()})."
43 )
44 )
46 if ti.task.end_date and logical_date > ti.task.end_date:
47 yield self._failing_status(
48 reason=(
49 f"The execution date is {logical_date.isoformat()} but this is "
50 f"after the task's end date {ti.task.end_date.isoformat()}."
51 )
52 )
54 if ti.task.dag and ti.task.dag.end_date and logical_date > ti.task.dag.end_date:
55 yield self._failing_status(
56 reason=(
57 f"The execution date is {logical_date.isoformat()} but this is after "
58 f"the task's DAG's end date {ti.task.dag.end_date.isoformat()}."
59 )
60 )