Лабораторная 4 — вложения и приватное S3

This commit is contained in:
2026-11-13 10:39:20 +03:00
parent ec540a1a72
commit 4cd025e477
62 changed files with 3545 additions and 22 deletions
+52
View File
@@ -0,0 +1,52 @@
"""Remove expired upload reservations and their S3 objects."""
import argparse
import logging
import time
from .attachments import AttachmentStorage
from .config import Config
from .db import Database
from .errors import Unavailable
from .store import Store
GRACE_SECONDS = 15 * 60
INTERVAL_SECONDS = 60
BATCH_SIZE = 25
def clean_batch(store, storage):
count = 0
while count < BATCH_SIZE and store.clean_pending_attachment(GRACE_SECONDS, storage.delete):
count += 1
return count
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--once', action='store_true', help='Process one bounded batch and exit')
args = parser.parse_args()
logging.basicConfig(level=logging.INFO)
config = Config.from_env()
database = Database(config)
store = Store(config, database, None)
storage = AttachmentStorage()
try:
database.open()
while True:
try:
deleted = clean_batch(store, storage)
if deleted or args.once:
logging.info('Expired attachment reservations removed: %s', deleted)
except Unavailable:
logging.warning('Attachment cleanup deferred because a dependency is unavailable')
if args.once:
return 1
if args.once:
return 0
time.sleep(INTERVAL_SECONDS)
finally:
database.close()
if __name__ == '__main__':
raise SystemExit(main())