ephraimbuddy commented on code in PR #63835:
URL: https://github.com/apache/airflow/pull/63835#discussion_r2987197178
##########
airflow-core/src/airflow/dag_processing/manager.py:
##########
@@ -592,6 +599,45 @@ def _add_callback_to_queue(self, request: CallbackRequest):
self._add_files_to_queue([file_info], mode="front")
Stats.incr("dag_processing.other_callback_count")
+ @provide_session
+ def get_bundle_state(self, bundle_name: str, *, session: Session =
NEW_SESSION) -> BundleState | None:
+ """
+ Return the persisted refresh state for a bundle.
+
+ Returns ``None`` if the bundle has no database record.
+ """
+ row = session.scalar(
+ select(DagBundleModel)
+ .where(DagBundleModel.name == bundle_name)
+ .options(load_only(DagBundleModel.last_refreshed,
DagBundleModel.version))
+ )
+ if row is None:
+ return None
+ return BundleState(last_refreshed=row.last_refreshed,
version=row.version)
+
+ @provide_session
+ def update_bundle_state(
+ self,
+ bundle_name: str,
+ *,
+ last_refreshed: datetime,
+ version: str | None,
+ session: Session = NEW_SESSION,
+ ) -> None:
+ """
+ Persist the post-refresh state for a bundle.
+
+ Always updates ``last_refreshed``. Updates ``version`` only when
``version`` is not
+ ``None`` — pass ``None`` to leave the stored version unchanged (e.g.
for non-versioned
+ bundles or when the version did not change after a refresh).
+ """
+ values: dict[str, Any] = {"last_refreshed": last_refreshed}
+ if version is not None:
+ values["version"] = version
+ session.execute(
+ update(DagBundleModel).where(DagBundleModel.name ==
bundle_name).values(**values)
+ )
Review Comment:
I didn't add this because of mysql. By default, in mysql, rowcount after an
update returns the number of rows changed, not rows matched. So if
last_refreshed happened to already equal now (e.g., two refresh cycles in the
same second), mysql would return 0 even though the row exists and was matched
--
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]