block: try to unify the mirror block modules

This commit is contained in:
Iain Learmonth 2022-06-18 12:36:54 +01:00
parent db0233691c
commit 360c786610
4 changed files with 114 additions and 109 deletions

View file

@ -78,18 +78,32 @@ class AbstractResource(db.Model): # type: ignore
def brn(self) -> BRN:
raise NotImplementedError()
def deprecate(self, *, reason: str) -> None:
def deprecate(self, *, reason: str) -> bool:
"""
Marks the resource as deprecated. In the event that the resource was already
deprecated, no change will be recorded and the function will return False.
:param reason: an opaque string that records the deprecation reason
:return: if the proxy was deprecated
"""
if self.deprecated is not None:
logging.info("Deprecating %s (reason=%s)", self.brn, reason)
self.deprecated = datetime.utcnow()
self.deprecation_reason = reason
self.updated = datetime.utcnow()
return True
else:
logging.info("Not deprecating %s (reason=%s) because it's already deprecated", self.brn, reason)
return False
def destroy(self) -> None:
"""
Marks the resource for destruction.
:return: None
"""
if self.deprecated is None:
self.deprecated = datetime.utcnow()
self.deprecate(reason="destroyed")
self.destroyed = datetime.utcnow()
self.updated = datetime.utcnow()