## 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."""TaskReschedule tracks rescheduled task instances."""from__future__importannotationsimportdatetimefromtypingimportTYPE_CHECKINGfromsqlalchemyimportColumn,ForeignKeyConstraint,Index,Integer,String,asc,desc,event,textfromsqlalchemy.ext.associationproxyimportassociation_proxyfromsqlalchemy.ormimportrelationshipfromairflow.models.baseimportCOLLATION_ARGS,ID_LEN,Basefromairflow.utils.sessionimportprovide_sessionfromairflow.utils.sqlalchemyimportUtcDateTimeifTYPE_CHECKING:fromairflow.models.baseoperatorimportBaseOperator
[docs]defquery_for_task_instance(task_instance,descending=False,session=None,try_number=None):""" Returns query for task reschedules for a given the task instance. :param session: the database session object :param task_instance: the task instance to find task reschedules for :param descending: If True then records are returned in descending order :param try_number: Look for TaskReschedule of the given try_number. Default is None which looks for the same try_number of the given task_instance. """iftry_numberisNone:try_number=task_instance.try_numberTR=TaskRescheduleqry=session.query(TR).filter(TR.dag_id==task_instance.dag_id,TR.task_id==task_instance.task_id,TR.run_id==task_instance.run_id,TR.map_index==task_instance.map_index,TR.try_number==try_number,)ifdescending:returnqry.order_by(desc(TR.id))else:returnqry.order_by(asc(TR.id))
@staticmethod@provide_session
[docs]deffind_for_task_instance(task_instance,session=None,try_number=None):""" Returns all task reschedules for the task instance and try number, in ascending order. :param session: the database session object :param task_instance: the task instance to find task reschedules for :param try_number: Look for TaskReschedule of the given try_number. Default is None which looks for the same try_number of the given task_instance. """returnTaskReschedule.query_for_task_instance(task_instance,session=session,try_number=try_number