dstandish commented on code in PR #46503:
URL: https://github.com/apache/airflow/pull/46503#discussion_r1968494590


##########
airflow/dag_processing/bundles/base.py:
##########
@@ -149,3 +362,72 @@ def lock(self):
             finally:
                 fcntl.flock(lock_file, fcntl.LOCK_UN)
                 self._locked = False
+
+    def __repr__(self):
+        return f"{self.__class__.__name__}(name={self.name})"
+
+
+class BundleVersionLock:
+    """
+    Lock version of bundle when in use to prevent deletion.
+
+    :meta private:
+    """
+
+    def __init__(self, bundle_name, bundle_version, **kwargs):
+        super().__init__(**kwargs)
+        self.bundle_name = bundle_name
+        self.version = bundle_version
+        self.lock_file_path = get_bundle_tracking_file(
+            bundle_name=self.bundle_name,
+            version=self.version,
+        )
+        self.lock_file = None
+
+    def _log_exc(self, msg):
+        log.exception(
+            "% name=%s version=%s lock_file=%s",
+            msg,
+            self.bundle_name,
+            self.version,
+            self.lock_file_path,
+        )
+
+    def _update_version_file(self):
+        """Create a version file containing last-used timestamp."""
+        self.lock_file_path.parent.mkdir(parents=True, exist_ok=True)
+
+        with tempfile.TemporaryDirectory() as td:
+            temp_file = Path(td, self.lock_file_path)

Review Comment:
   i don't really like working with NamedTemporaryFile.  It also feels weird to 
create a temporary file that ... you are going to keep



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