included rabbitmq as broker
This commit is contained in:
+7
-3
@@ -6,19 +6,22 @@ from dataclasses import asdict
|
||||
import json
|
||||
|
||||
from app.core.config import Settings
|
||||
from app.core.jobs import JobSettings
|
||||
from app.core.database import create_db_engine, create_session_factory
|
||||
from app.core.s3 import S3Settings
|
||||
from app.domain.attachments import reconcile_attachments
|
||||
from app.domain.attachment_jobs import cleanup_staging
|
||||
from app.errors.handlers import RECOVERABLE_STORAGE_ERRORS, log_recoverable_error
|
||||
from app.storage.s3 import create_s3_storage
|
||||
|
||||
|
||||
async def cleanup_once(factory, storage, apply: bool) -> bool:
|
||||
async def cleanup_once(factory, storage, apply: bool, jobs: JobSettings) -> bool:
|
||||
completed = True
|
||||
try:
|
||||
async with factory() as session:
|
||||
result = await reconcile_attachments(session, storage, dry_run=not apply)
|
||||
print(json.dumps(asdict(result)), flush=True)
|
||||
staging = await cleanup_staging(session, storage, jobs, apply=apply)
|
||||
print(json.dumps({**asdict(result), "terminal_staging": staging}), flush=True)
|
||||
except RECOVERABLE_STORAGE_ERRORS as error:
|
||||
log_recoverable_error("Reconciliation", error)
|
||||
completed = False
|
||||
@@ -28,12 +31,13 @@ async def cleanup_once(factory, storage, apply: bool) -> bool:
|
||||
async def run(once: bool, apply: bool) -> None:
|
||||
settings = Settings() # type: ignore
|
||||
s3_settings = S3Settings()
|
||||
jobs = JobSettings()
|
||||
engine = create_db_engine(settings)
|
||||
factory = create_session_factory(engine)
|
||||
storage = create_s3_storage(s3_settings)
|
||||
try:
|
||||
while True:
|
||||
completed = await cleanup_once(factory, storage, apply)
|
||||
completed = await cleanup_once(factory, storage, apply, jobs)
|
||||
if once:
|
||||
if not completed:
|
||||
raise SystemExit(1)
|
||||
|
||||
Reference in New Issue
Block a user