airflow.models.dagrun

Module Contents

Classes

TISchedulingDecision

Type of return for DagRun.task_instance_scheduling_decisions

DagRun

DagRun describes an instance of a Dag. It can be created

DagRunNote

For storage of arbitrary notes concerning the dagrun instance.

Attributes

CreatedTasks

airflow.models.dagrun.CreatedTasks[source]
class airflow.models.dagrun.TISchedulingDecision[source]

Bases: NamedTuple

Type of return for DagRun.task_instance_scheduling_decisions

tis: list[airflow.models.taskinstance.TaskInstance][source]
schedulable_tis: list[airflow.models.taskinstance.TaskInstance][source]
changed_tis: bool[source]
unfinished_tis: list[airflow.models.taskinstance.TaskInstance][source]
finished_tis: list[airflow.models.taskinstance.TaskInstance][source]
class airflow.models.dagrun.DagRun(dag_id=None, run_id=None, queued_at=NOTSET, execution_date=None, start_date=None, external_trigger=None, conf=None, state=None, run_type=None, dag_hash=None, creating_job_id=None, data_interval=None)[source]

Bases: airflow.models.base.Base, airflow.utils.log.logging_mixin.LoggingMixin

DagRun describes an instance of a Dag. It can be created by the scheduler (for regular runs) or by an external trigger

property logical_date: datetime.datetime[source]
property state[source]
property is_backfill: bool[source]
__tablename__ = 'dag_run'[source]
id[source]
dag_id[source]
queued_at[source]
execution_date[source]
start_date[source]
end_date[source]
run_id[source]
creating_job_id[source]
external_trigger[source]
run_type[source]
conf[source]
data_interval_start[source]
data_interval_end[source]
last_scheduling_decision[source]
dag_hash[source]
log_template_id[source]
updated_at[source]
__table_args__ = ()[source]
task_instances[source]
dag_model[source]
dag_run_note[source]
note[source]
DEFAULT_DAGRUNS_TO_EXAMINE[source]
__repr__()[source]

Return repr(self).

get_state()[source]
set_state(state)[source]
refresh_from_db(session=NEW_SESSION)[source]

Reloads the current dagrun from the database

Parameters

session (sqlalchemy.orm.session.Session) -- database session

classmethod active_runs_of_dags(dag_ids=None, only_running=False, session=None)[source]

Get the number of active dag runs for each dag.

classmethod next_dagruns_to_examine(state, session, max_number=None)[source]

Return the next DagRuns that the scheduler should attempt to schedule.

This will return zero or more DagRun rows that are row-level-locked with a "SELECT ... FOR UPDATE" query, you should ensure that any scheduling decisions are made in a single transaction -- as soon as the transaction is committed it will be unlocked.

classmethod find(dag_id=None, run_id=None, execution_date=None, state=None, external_trigger=None, no_backfills=False, run_type=None, session=NEW_SESSION, execution_start_date=None, execution_end_date=None)[source]

Returns a set of dag runs for the given search criteria.

Parameters
  • dag_id (str | list[str] | None) -- the dag_id or list of dag_id to find dag runs for

  • run_id (Iterable[str] | None) -- defines the run id for this dag run

  • run_type (DagRunType | None) -- type of DagRun

  • execution_date (datetime | Iterable[datetime] | None) -- the execution date

  • state (DagRunState | None) -- the state of the dag run

  • external_trigger (bool | None) -- whether this dag run is externally triggered

  • no_backfills (bool) -- return no backfills (True), return all (False). Defaults to False

  • session (sqlalchemy.orm.session.Session) -- database session

  • execution_start_date (datetime | None) -- dag run that was executed from this date

  • execution_end_date (datetime | None) -- dag run that was executed until this date

classmethod find_duplicate(dag_id, run_id, execution_date, session=NEW_SESSION)[source]

Return an existing run for the DAG with a specific run_id or execution_date.

None is returned if no such DAG run is found.

Parameters
static generate_run_id(run_type, execution_date)[source]

Generate Run ID based on Run Type and Execution Date

get_task_instances(state=None, session=NEW_SESSION)[source]

Returns the task instances for this dag run

get_task_instance(task_id, session=NEW_SESSION, *, map_index=-1)[source]

Returns the task instance specified by task_id for this dag run

Parameters
get_dag()[source]

Returns the Dag associated with this DagRun.

Returns

DAG

Return type

airflow.models.dag.DAG

get_previous_dagrun(state=None, session=NEW_SESSION)[source]

The previous DagRun, if there is one

get_previous_scheduled_dagrun(session=NEW_SESSION)[source]

The previous, SCHEDULED DagRun, if there is one

update_state(session=NEW_SESSION, execute_callbacks=True)[source]

Determines the overall state of the DagRun based on the state of its TaskInstances.

Parameters
  • session (sqlalchemy.orm.session.Session) -- Sqlalchemy ORM Session

  • execute_callbacks (bool) -- Should dag callbacks (success/failure, SLA etc.) be invoked directly (default: true) or recorded as a pending request in the returned_callback property

Returns

Tuple containing tis that can be scheduled in the current loop & returned_callback that needs to be executed

Return type

tuple[list[airflow.models.taskinstance.TaskInstance], DagCallbackRequest | None]

task_instance_scheduling_decisions(session=NEW_SESSION)[source]
notify_dagrun_state_changed(msg='')[source]
verify_integrity(*, session=NEW_SESSION)[source]

Verifies the DagRun by checking for removed tasks or tasks that are not in the database yet. It will set state to removed or add the task if required.

Missing_indexes

A dictionary of task vs indexes that are missing.

Parameters

session (sqlalchemy.orm.session.Session) -- Sqlalchemy ORM Session

static get_run(session, dag_id, execution_date)[source]

Get a single DAG Run

Parameters
Returns

DagRun corresponding to the given dag_id and execution date if one exists. None otherwise.

Return type

DagRun | None

classmethod get_latest_runs(session=None)[source]

Returns the latest DagRun for each DAG

schedule_tis(schedulable_tis, session=NEW_SESSION)[source]

Set the given task instances in to the scheduled state.

Each element of schedulable_tis should have it's task attribute already set.

Any EmptyOperator without callbacks or outlets is instead set straight to the success state.

All the TIs should belong to this DagRun, but this code is in the hot-path, this is not checked -- it is the caller's responsibility to call this function only with TIs from a single dag run.

get_log_template(*, session=NEW_SESSION)[source]
get_log_filename_template(*, session=NEW_SESSION)[source]
class airflow.models.dagrun.DagRunNote(content, user_id=None)[source]

Bases: airflow.models.base.Base

For storage of arbitrary notes concerning the dagrun instance.

__tablename__ = 'dag_run_note'[source]
user_id[source]
dag_run_id[source]
content[source]
created_at[source]
updated_at[source]
dag_run[source]
__table_args__ = ()[source]
__repr__()[source]

Was this entry helpful?