mirrors: deprecate orphaned proxies

fixes #5
This commit is contained in:
Iain Learmonth 2022-05-08 10:47:01 +01:00
parent bd73255824
commit 9b8ac493b1
3 changed files with 18 additions and 4 deletions

View file

@ -41,6 +41,17 @@ class ProxyAutomation(BaseAutomation):
db.session.add(proxy)
db.session.commit()
def deprecate_orphaned_proxies(self):
proxies = Proxy.query.filter(
Proxy.destroyed == None,
Proxy.provider == self.provider,
Proxy.deprecated == None
).all()
for proxy in proxies:
if proxy.origin.destroyed is not None:
proxy.deprecate(reason="origin_destroyed")
db.session.commit()
def destroy_expired_proxies(self):
cutoff = datetime.datetime.utcnow() - datetime.timedelta(days=3)
proxies = Proxy.query.filter(
@ -53,6 +64,11 @@ class ProxyAutomation(BaseAutomation):
proxy.updated = datetime.datetime.utcnow()
db.session.commit()
def pre_housekeeping(self):
self.create_missing_proxies()
self.deprecate_orphaned_proxies()
self.destroy_expired_proxies()
def generate_terraform(self):
self.write_terraform_config(
self.template,