Prechádzať zdrojové kódy

[task] Log when we don't find a task for notes

Colin Powell 8 mesiacov pred
rodič
commit
82dcad569a

+ 18 - 8
vrobbler/apps/scrobbles/scrobblers.py

@@ -327,21 +327,31 @@ def todoist_scrobble_update_task(
         log__task_id=todoist_note.get("task_id"),
     ).first()
 
-    if scrobble:
-        existing_notes = scrobble.log.get("notes", {})
-        existing_notes[todoist_note.get("todoist_id")] = todoist_note.get(
-            "content"
-        )
-        scrobble.log["notes"] = existing_notes
-        scrobble.save(update_fields=["log"])
+    if not scrobble:
         logger.info(
-            "[todoist_scrobble_update_task] todoist note added",
+            "[todoist_scrobble_update_task] no task found",
             extra={
                 "todoist_note": todoist_note,
                 "user_id": user_id,
                 "media_type": Scrobble.MediaType.TASK,
             },
         )
+        return
+
+    existing_notes = scrobble.log.get("notes", {})
+    existing_notes[todoist_note.get("todoist_id")] = todoist_note.get(
+        "content"
+    )
+    scrobble.log["notes"] = existing_notes
+    scrobble.save(update_fields=["log"])
+    logger.info(
+        "[todoist_scrobble_update_task] todoist note added",
+        extra={
+            "todoist_note": todoist_note,
+            "user_id": user_id,
+            "media_type": Scrobble.MediaType.TASK,
+        },
+    )
 
     return scrobble
 

+ 4 - 0
vrobbler/apps/tasks/webhooks.py

@@ -103,6 +103,10 @@ def todoist_webhook(request):
         scrobble = todoist_scrobble_update_task(todoist_note, user_id)
 
     if not scrobble:
+        logger.info(
+            "[todoist_webhook] finished with no note or task found",
+            extra={"scrobble_id": None},
+        )
         return Response(
             {"error": "No scrobble found to be updated"},
             status=status.HTTP_304_NOT_MODIFIED,