From 74f93ef856947efdaa30241e8adfbe2383cdd13d Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:28:28 +0000 Subject: [PATCH] catch cached inserts --- src/main.py | 2 +- src/worker.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main.py b/src/main.py index c90b3ce..a6864c9 100644 --- a/src/main.py +++ b/src/main.py @@ -25,7 +25,7 @@ load_dotenv() # Configuration ALLOWED_ORIGINS = os.environ.get("ALLOWED_ORIGINS", "chrome-extension://ondkcheoicfckabcnkdgbepofpjmjcmb,chrome-extension://ojcimmjndnlmmlgnjaeojoebaceokpdp").split(",") -VERSION = "0.5.10" +VERSION = "0.5.11" # min-version refers to the version of auto-archiver-extension on the webstore BREAKING_CHANGES = {"minVersion": "0.3.1", "message": "The latest update has breaking changes, please update the extension to the most recent version."} diff --git a/src/worker.py b/src/worker.py index 1baaca0..0ef16fd 100644 --- a/src/worker.py +++ b/src/worker.py @@ -13,7 +13,7 @@ from db.database import SessionLocal from contextlib import contextmanager import json -from security import ALLOW_ANY_EMAIL +from sqlite3 import IntegrityError celery = Celery(__name__) celery.conf.broker_url = os.environ.get("CELERY_BROKER_URL", "redis://localhost:6379") @@ -77,11 +77,17 @@ def create_sheet_task(self, sheet_json: str): try: insert_result_into_db(result, sheet.tags, sheet.public, sheet.group_id, sheet.author_id, models.generate_uuid()) stats["archived"] += 1 + except IntegrityError as e: + # cache was used, so we skip + logger.warning(f"cached result detected: {e}") + logger.warning(traceback.format_exc()) + stats["archived"] += 1 + pass except Exception as e: logger.error(e) logger.error(traceback.format_exc()) stats["failed"] += 1 - stats["errors"].append(e) + stats["errors"].append(str(e)) logger.info(f"SHEET DONE {sheet=}") return {"success": True, "sheet": sheet.sheet_name, "sheet_id": sheet.sheet_id, "time": datetime.datetime.now().isoformat(), **stats}