Run initial retention checks regardless of host uptime
This commit is contained in:
@@ -101,7 +101,7 @@ class CloudLibrary:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def sweep(self):
|
def sweep(self):
|
||||||
if time.monotonic() - self.checked < 60:
|
if self.checked and time.monotonic() - self.checked < 60:
|
||||||
return
|
return
|
||||||
self.checked = time.monotonic()
|
self.checked = time.monotonic()
|
||||||
with self.service.lock:
|
with self.service.lock:
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class Retention:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def sweep(self):
|
def sweep(self):
|
||||||
if time.monotonic() - self.checked < 3600:
|
if self.checked and time.monotonic() - self.checked < 3600:
|
||||||
return
|
return
|
||||||
self.checked = time.monotonic()
|
self.checked = time.monotonic()
|
||||||
with self.service.lock:
|
with self.service.lock:
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ class LocalRetention:
|
|||||||
}
|
}
|
||||||
|
|
||||||
def sweep(self, force=False, dry_run=False):
|
def sweep(self, force=False, dry_run=False):
|
||||||
if not force and time.monotonic() - self.last < 3600:
|
if not force and self.last and time.monotonic() - self.last < 3600:
|
||||||
return {}
|
return {}
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
self.last = time.monotonic()
|
self.last = time.monotonic()
|
||||||
|
|||||||
@@ -151,3 +151,24 @@ def test_cleanup_option_requires_random_photo_job():
|
|||||||
source={"type": "template", "template": "quote"},
|
source={"type": "template", "template": "quote"},
|
||||||
cleanup_unstarred=True,
|
cleanup_unstarred=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_first_cleanup_runs_after_recent_host_boot(
|
||||||
|
client, service, settings, monkeypatch
|
||||||
|
):
|
||||||
|
image_id = upload_random(client, service, settings)
|
||||||
|
due(service, image_id)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"pigway_frame_flow.display.retention.time.monotonic", lambda: 120
|
||||||
|
)
|
||||||
|
service.retention.sweep()
|
||||||
|
row = service.db.one("SELECT * FROM image_retention WHERE image_id=?", (image_id,))
|
||||||
|
assert row["cleanup_operation"]
|
||||||
|
assert service.retention.checked == 120
|
||||||
|
service.retention.sweep()
|
||||||
|
assert (
|
||||||
|
service.db.one("SELECT COUNT(*) AS n FROM operations WHERE action='delete'")[
|
||||||
|
"n"
|
||||||
|
]
|
||||||
|
== 1
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user