ashb commented on code in PR #54103:
URL: https://github.com/apache/airflow/pull/54103#discussion_r2285132956
##########
airflow-core/tests/unit/jobs/test_scheduler_job.py:
##########
@@ -180,6 +180,39 @@ def _create_dagrun(
return _create_dagrun
+def task_maker(dag_maker, session, dag_id: str, task_num: int,
max_active_tasks: int):
+ dag_tasks = {}
+
+ with dag_maker(dag_id=dag_id):
+ for i in range(task_num):
+ # Assign priority weight to certain tasks.
+ if (i % 10) == 0: # 10, 20, 30, 40, 50, ...
+ weight = int(i / 2)
+ dag_tasks[f"op{i}"] = EmptyOperator(task_id=f"dummy{i}",
priority_weight=weight)
+ else:
+ # No executor specified, runs on default executor
+ dag_tasks[f"op{i}"] = EmptyOperator(task_id=f"dummy{i}")
+
+ # 'logical_date' is used to create the 'run_id'. Set it to 'now', in order
to get distinct run ids.
+ dag_run = dag_maker.create_dagrun(run_type=DagRunType.SCHEDULED,
logical_date=timezone.utcnow())
+
+ task_tis = {}
+
+ tis_list = []
+ for i in range(task_num):
+ task_tis[f"ti{i}"] =
dag_run.get_task_instance(dag_tasks[f"op{i}"].task_id, session)
+ # Add to the list.
+ tis_list.append(task_tis[f"ti{i}"])
+
+ for ti in tis_list:
+ ti.state = State.SCHEDULED
+ ti.dag_model.max_active_tasks = max_active_tasks
+
+ session.flush()
+
+ return tis_list
Review Comment:
Yeah that makes sense. I first read it as a test that wasn't testing much
and was confused.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]