Commit d04f22e
authored
Clarify a bit the code re updating next_dag run and next run after (#59724)
Currently it's a bit complicated and confusing. It somewhat remains so after this update, but hopefully a little improved.
For example we have an argument "last automated dagrun" that takes not a dag run but a data interval.
And, when we call it, in places in the scheduler, we may call it with a run that is not actually "the last automated dagrun" -- it could be any dag run the scheduler touches, which of course could be a very old dag run.
I don't solve that problem here.
But I do try to make things a little clearer and a little simpler at the scheduler call sites.
In particular, there were two things that bothered me.
1. in the function `_should_update_dag_next_dagruns`, we did not only *check* whether we should update. In some branches we actually *did* the update then said "no, don't update." I pull this update higher up where it's more visible.
2. it's not obvious that the `calculate_dagrun_date_fields` function actually mutates the dag. It just says "calculate," right? So, to improve this slightly, and to reduce noise a bit at call site, I wrap this (along with the update mentioned above) in a function called `_update_next_dagrun_fields`. At least it's clear we are (at least probably) updating the dag fields. This has the side benefit bringing all invocations of `calculate_dagrun_date_fields` into one function in the scheduler (which is invoked in a few places).
So hopefully modest clarity improvement, and hopefully no behavior change.
Also -- discovered something very not obvious about this logic.
If you passed dag run to it after dag run created, then it would never update the fields. but this is probably the most important time to do the update, so teh scheduler doesn't try to create the same dagrun again.
So to prevent ogainst this confusing scenario, I just pull that logic out of this function and move it to the specific call sites where it is required -- only in the scheduling (not dagrun creation) context.1 parent 4d5e108 commit d04f22e
File tree
2 files changed
+116
-75
lines changed- airflow-core
- src/airflow/jobs
- tests/unit/jobs
2 files changed
+116
-75
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
| |||
1846 | 1847 | | |
1847 | 1848 | | |
1848 | 1849 | | |
1849 | | - | |
1850 | | - | |
1851 | | - | |
1852 | | - | |
1853 | | - | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
1854 | 1853 | | |
1855 | | - | |
1856 | | - | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
1857 | 1858 | | |
1858 | 1859 | | |
1859 | 1860 | | |
| |||
1933 | 1934 | | |
1934 | 1935 | | |
1935 | 1936 | | |
1936 | | - | |
1937 | | - | |
1938 | | - | |
1939 | | - | |
1940 | | - | |
1941 | | - | |
1942 | | - | |
1943 | | - | |
1944 | | - | |
1945 | | - | |
1946 | | - | |
1947 | | - | |
1948 | | - | |
1949 | | - | |
1950 | | - | |
1951 | | - | |
1952 | | - | |
1953 | | - | |
1954 | | - | |
1955 | | - | |
1956 | | - | |
1957 | | - | |
1958 | | - | |
1959 | | - | |
1960 | | - | |
1961 | | - | |
1962 | | - | |
1963 | | - | |
1964 | | - | |
1965 | | - | |
1966 | | - | |
1967 | | - | |
1968 | | - | |
1969 | | - | |
1970 | | - | |
1971 | | - | |
1972 | | - | |
1973 | | - | |
1974 | | - | |
1975 | 1937 | | |
1976 | 1938 | | |
1977 | 1939 | | |
| |||
2147 | 2109 | | |
2148 | 2110 | | |
2149 | 2111 | | |
2150 | | - | |
| 2112 | + | |
2151 | 2113 | | |
2152 | 2114 | | |
2153 | 2115 | | |
2154 | 2116 | | |
2155 | 2117 | | |
2156 | 2118 | | |
2157 | | - | |
2158 | | - | |
2159 | | - | |
2160 | 2119 | | |
2161 | 2120 | | |
2162 | 2121 | | |
| |||
2176 | 2135 | | |
2177 | 2136 | | |
2178 | 2137 | | |
2179 | | - | |
2180 | | - | |
2181 | | - | |
2182 | | - | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
| 2147 | + | |
| 2148 | + | |
2183 | 2149 | | |
2184 | 2150 | | |
2185 | 2151 | | |
| |||
2252 | 2218 | | |
2253 | 2219 | | |
2254 | 2220 | | |
2255 | | - | |
2256 | | - | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
2257 | 2233 | | |
2258 | 2234 | | |
2259 | 2235 | | |
| |||
2270 | 2246 | | |
2271 | 2247 | | |
2272 | 2248 | | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
| 2282 | + | |
| 2283 | + | |
| 2284 | + | |
| 2285 | + | |
| 2286 | + | |
| 2287 | + | |
| 2288 | + | |
| 2289 | + | |
2273 | 2290 | | |
2274 | 2291 | | |
2275 | 2292 | | |
| |||
3001 | 3018 | | |
3002 | 3019 | | |
3003 | 3020 | | |
| 3021 | + | |
| 3022 | + | |
| 3023 | + | |
| 3024 | + | |
| 3025 | + | |
| 3026 | + | |
| 3027 | + | |
| 3028 | + | |
| 3029 | + | |
| 3030 | + | |
| 3031 | + | |
| 3032 | + | |
| 3033 | + | |
| 3034 | + | |
| 3035 | + | |
| 3036 | + | |
| 3037 | + | |
3004 | 3038 | | |
3005 | 3039 | | |
3006 | 3040 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
4421 | 4421 | | |
4422 | 4422 | | |
4423 | 4423 | | |
| 4424 | + | |
4424 | 4425 | | |
4425 | | - | |
| 4426 | + | |
4426 | 4427 | | |
4427 | 4428 | | |
4428 | 4429 | | |
| |||
4444 | 4445 | | |
4445 | 4446 | | |
4446 | 4447 | | |
4447 | | - | |
4448 | | - | |
4449 | | - | |
4450 | | - | |
4451 | | - | |
4452 | | - | |
4453 | | - | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
| 4451 | + | |
| 4452 | + | |
| 4453 | + | |
| 4454 | + | |
| 4455 | + | |
| 4456 | + | |
4454 | 4457 | | |
4455 | 4458 | | |
4456 | 4459 | | |
| |||
4472 | 4475 | | |
4473 | 4476 | | |
4474 | 4477 | | |
4475 | | - | |
| 4478 | + | |
4476 | 4479 | | |
4477 | 4480 | | |
4478 | | - | |
4479 | | - | |
4480 | 4481 | | |
4481 | 4482 | | |
4482 | 4483 | | |
| |||
4490 | 4491 | | |
4491 | 4492 | | |
4492 | 4493 | | |
4493 | | - | |
4494 | | - | |
4495 | | - | |
4496 | | - | |
4497 | | - | |
4498 | | - | |
4499 | | - | |
| 4494 | + | |
| 4495 | + | |
| 4496 | + | |
| 4497 | + | |
| 4498 | + | |
| 4499 | + | |
| 4500 | + | |
| 4501 | + | |
| 4502 | + | |
| 4503 | + | |
| 4504 | + | |
| 4505 | + | |
| 4506 | + | |
4500 | 4507 | | |
4501 | 4508 | | |
4502 | 4509 | | |
| |||
0 commit comments