uranusjr commented on code in PR #29094:
URL: https://github.com/apache/airflow/pull/29094#discussion_r1149027949


##########
airflow/jobs/scheduler_job.py:
##########
@@ -83,6 +84,17 @@
 DM = DagModel
 
 
+@dataclass
+class ConcurrencyMap:
+    """Dataclass to represent concurrency maps"""
+
+    dag_active_tasks_map: DefaultDict[str, int] = 
field(default_factory=lambda: defaultdict(int))
+    task_concurrency_map: DefaultDict[tuple[str, str], int] = 
field(default_factory=lambda: defaultdict(int))
+    task_dagrun_concurrency_map: DefaultDict[tuple[str, str, str], int] = 
field(
+        default_factory=lambda: defaultdict(int)
+    )

Review Comment:
   I wonder if using a `Counter` and a `classmethod` would help with 
implementation (illustrative code, please revise)
   
   ```python
   @dataclass
   class ConcurrencyMap:
       dag_active_tasks_map: dict[str, int]
       task_concurrency_map: dict[tuple[str, str], int]
       task_dagrun_concurrency_map: dict[tuple[str, str, str], int]
   
       @classmethod
       def read_ti_concurrency_query(cls) -> Self:
           query = ...
           mapping = {(d, r, t): c for d, r, t, c in query}
           instance = cls(Counter(), Counter(), mapping)
           for (d, r, t), c in mapping.items():
               concurrency_map.dag_active_tasks_map[d] += c
               concurrency_map.task_concurrency_map[(d, t)] += c
           return instance
   ```



##########
airflow/jobs/scheduler_job.py:
##########
@@ -83,6 +84,17 @@
 DM = DagModel
 
 
+@dataclass
+class ConcurrencyMap:
+    """Dataclass to represent concurrency maps"""
+
+    dag_active_tasks_map: DefaultDict[str, int] = 
field(default_factory=lambda: defaultdict(int))
+    task_concurrency_map: DefaultDict[tuple[str, str], int] = 
field(default_factory=lambda: defaultdict(int))
+    task_dagrun_concurrency_map: DefaultDict[tuple[str, str, str], int] = 
field(
+        default_factory=lambda: defaultdict(int)
+    )

Review Comment:
   I wonder if using a `Counter` and a `classmethod` would help with 
implementation (illustrative code, please revise)
   
   ```python
   @dataclass
   class ConcurrencyMap:
       dag_active_tasks_map: dict[str, int]
       task_concurrency_map: dict[tuple[str, str], int]
       task_dagrun_concurrency_map: dict[tuple[str, str, str], int]
   
       @classmethod
       def read_ti_concurrency_query(cls) -> Self:
           query = ...
           mapping = {(d, r, t): c for d, r, t, c in query}
           instance = cls(Counter(), Counter(), mapping)
           for (d, r, t), c in mapping.items():
               instance.dag_active_tasks_map[d] += c
               instance.task_concurrency_map[(d, t)] += c
           return instance
   ```



-- 
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]

Reply via email to