-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run the task with the configured dag bundle
- Loading branch information
Showing
5 changed files
with
100 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,7 @@ | |
UnknownExecutorException, | ||
) | ||
from airflow.executors.executor_loader import ExecutorLoader | ||
from airflow.executors.workloads import DagBundle | ||
from airflow.models.asset import ( | ||
AssetDagRunQueue, | ||
AssetModel, | ||
|
@@ -241,51 +242,6 @@ def _triggerer_is_healthy(): | |
return job and job.is_alive() | ||
|
||
|
||
@provide_session | ||
def _create_orm_dagrun( | ||
dag, | ||
dag_id, | ||
run_id, | ||
logical_date, | ||
start_date, | ||
external_trigger, | ||
conf, | ||
state, | ||
run_type, | ||
dag_version, | ||
creating_job_id, | ||
data_interval, | ||
backfill_id, | ||
session, | ||
triggered_by, | ||
): | ||
run = DagRun( | ||
dag_id=dag_id, | ||
run_id=run_id, | ||
logical_date=logical_date, | ||
start_date=start_date, | ||
external_trigger=external_trigger, | ||
conf=conf, | ||
state=state, | ||
run_type=run_type, | ||
dag_version=dag_version, | ||
creating_job_id=creating_job_id, | ||
data_interval=data_interval, | ||
triggered_by=triggered_by, | ||
backfill_id=backfill_id, | ||
) | ||
# Load defaults into the following two fields to ensure result can be serialized detached | ||
run.log_template_id = int(session.scalar(select(func.max(LogTemplate.__table__.c.id)))) | ||
run.consumed_asset_events = [] | ||
session.add(run) | ||
session.flush() | ||
run.dag = dag | ||
# create the associated task instances | ||
# state is None at the moment of creation | ||
run.verify_integrity(session=session) | ||
return run | ||
|
||
|
||
if TYPE_CHECKING: | ||
dag = task_sdk_dag_decorator | ||
else: | ||
|
@@ -1957,6 +1913,55 @@ def get_num_task_instances(dag_id, run_id=None, task_ids=None, states=None, sess | |
return session.scalar(qry) | ||
|
||
|
||
@provide_session | ||
def _create_orm_dagrun( | ||
dag: DAG, | ||
dag_id, | ||
run_id, | ||
logical_date, | ||
start_date, | ||
external_trigger, | ||
conf, | ||
state, | ||
run_type, | ||
dag_version, | ||
creating_job_id, | ||
data_interval, | ||
backfill_id, | ||
session, | ||
triggered_by, | ||
): | ||
bundle_version = session.scalar( | ||
select(DagModel.latest_bundle_version).where(DagModel.dag_id == dag.dag_id) | ||
) | ||
run = DagRun( | ||
dag_id=dag_id, | ||
run_id=run_id, | ||
logical_date=logical_date, | ||
start_date=start_date, | ||
external_trigger=external_trigger, | ||
conf=conf, | ||
state=state, | ||
run_type=run_type, | ||
dag_version=dag_version, | ||
creating_job_id=creating_job_id, | ||
data_interval=data_interval, | ||
triggered_by=triggered_by, | ||
backfill_id=backfill_id, | ||
bundle_version=bundle_version, | ||
) | ||
# Load defaults into the following two fields to ensure result can be serialized detached | ||
run.log_template_id = int(session.scalar(select(func.max(LogTemplate.__table__.c.id)))) | ||
run.consumed_asset_events = [] | ||
session.add(run) | ||
session.flush() | ||
run.dag = dag | ||
# create the associated task instances | ||
# state is None at the moment of creation | ||
run.verify_integrity(session=session) | ||
return run | ||
|
||
|
||
class DagTag(Base): | ||
"""A tag name per dag, to allow quick filtering in the DAG view.""" | ||
|
||
|
@@ -2002,6 +2007,18 @@ def get_all(cls, session) -> dict[str, dict[str, str]]: | |
return dag_links | ||
|
||
|
||
bundle = DagBundle.model_construct( | ||
name="my-bundle", | ||
classpath="airflow.dag_processing.bundles.git.GitDagBundle", | ||
kwargs={ | ||
"repo_url": "[email protected]:dstandish/my-dags.git", | ||
"tracking_ref": "main", | ||
"subdir": "dags", | ||
}, | ||
version="dd4399e", | ||
) | ||
|
||
|
||
class DagModel(Base): | ||
"""Table containing DAG properties.""" | ||
|
||
|
@@ -2093,6 +2110,10 @@ class DagModel(Base): | |
"DagVersion", back_populates="dag_model", cascade="all, delete, delete-orphan" | ||
) | ||
|
||
# todo: uncomment this when parsing side is "there" | ||
# dag_bundle = relationship("DagBundle") | ||
dag_bundle = bundle | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
if self.max_active_tasks is None: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters