Skip to content

Commit

Permalink
Add new run type "triggered" to separate manual DAG runs and triggere…
Browse files Browse the repository at this point in the history
…d DAG runs (TriggerDagRunOperator)
  • Loading branch information
molcay committed Jan 29, 2024
1 parent 1197f2f commit cd8976b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion airflow/operators/trigger_dagrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def execute(self, context: Context):
if self.trigger_run_id:
run_id = str(self.trigger_run_id)
else:
run_id = DagRun.generate_run_id(DagRunType.MANUAL, parsed_execution_date)
run_id = DagRun.generate_run_id(DagRunType.TRIGGERED, parsed_execution_date)

try:
dag_run = trigger_dag(
Expand Down
1 change: 1 addition & 0 deletions airflow/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class DagRunType(str, enum.Enum):
SCHEDULED = "scheduled"
MANUAL = "manual"
DATASET_TRIGGERED = "dataset_triggered"
TRIGGERED = "triggered"

def __str__(self) -> str:
return self.value
Expand Down
4 changes: 3 additions & 1 deletion airflow/www/static/js/components/RunTypeIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import React from "react";
import { MdPlayArrow, MdOutlineSchedule } from "react-icons/md";
import { MdPlayArrow, MdOutlineSchedule, MdBolt } from "react-icons/md";
import { RiArrowGoBackFill } from "react-icons/ri";
import { HiDatabase } from "react-icons/hi";

Expand All @@ -44,6 +44,8 @@ const DagRunTypeIcon = ({ runType, ...rest }: Props) => {
return <MdOutlineSchedule style={iconStyle} {...rest} />;
case "dataset_triggered":
return <HiDatabase style={iconStyle} {...rest} />;
case "triggered":
return <MdBolt style={iconStyle} {...rest} />;
default:
return null;
}
Expand Down
7 changes: 6 additions & 1 deletion airflow/www/static/js/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ interface Dag {

interface DagRun {
runId: string;
runType: "manual" | "backfill" | "scheduled" | "dataset_triggered";
runType:
| "manual"
| "backfill"
| "scheduled"
| "dataset_triggered"
| "triggered";
state: RunState;
executionDate: string;
dataIntervalStart: string;
Expand Down
4 changes: 2 additions & 2 deletions tests/operators/test_trigger_dagrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_trigger_dagrun(self):
with create_session() as session:
dagrun = session.query(DagRun).filter(DagRun.dag_id == TRIGGERED_DAG_ID).one()
assert dagrun.external_trigger
assert dagrun.run_id == DagRun.generate_run_id(DagRunType.MANUAL, dagrun.execution_date)
assert dagrun.run_id == DagRun.generate_run_id(DagRunType.TRIGGERED, dagrun.execution_date)
self.assert_extra_link(dagrun, task, session)

def test_trigger_dagrun_custom_run_id(self):
Expand Down Expand Up @@ -154,7 +154,7 @@ def test_trigger_dagrun_with_execution_date(self):
dagrun = session.query(DagRun).filter(DagRun.dag_id == TRIGGERED_DAG_ID).one()
assert dagrun.external_trigger
assert dagrun.execution_date == custom_execution_date
assert dagrun.run_id == DagRun.generate_run_id(DagRunType.MANUAL, custom_execution_date)
assert dagrun.run_id == DagRun.generate_run_id(DagRunType.TRIGGERED, custom_execution_date)
self.assert_extra_link(dagrun, task, session)

def test_trigger_dagrun_twice(self):
Expand Down

0 comments on commit cd8976b

Please sign in to comment.