[tasks] Fix catch for no scrobble available
This commit is contained in:
@ -310,15 +310,24 @@ def manual_scrobble_from_url(url: str, user_id: int) -> Scrobble:
|
|||||||
return eval(scrobble_fn)(item_id, user_id)
|
return eval(scrobble_fn)(item_id, user_id)
|
||||||
|
|
||||||
|
|
||||||
def todoist_scrobble_task_finish(todoist_task: dict, user_id: int) -> Scrobble:
|
def todoist_scrobble_task_finish(
|
||||||
|
todoist_task: dict, user_id: int
|
||||||
|
) -> Optional[Scrobble]:
|
||||||
scrobble = Scrobble.objects.filter(
|
scrobble = Scrobble.objects.filter(
|
||||||
user_id=user_id, log__todoist_id=todoist_task.get("todoist_id")
|
user_id=user_id, log__todoist_id=todoist_task.get("todoist_id")
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
|
if not scrobble:
|
||||||
|
logger.info(
|
||||||
|
"[todoist_scrobble_task_finish] todoist webhook finish called on missing task"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
if not scrobble.in_progress or scrobble.played_to_completion:
|
if not scrobble.in_progress or scrobble.played_to_completion:
|
||||||
logger.warning(
|
logger.info(
|
||||||
"[todoist_scrobble_task_finish] todoist webhook finish called on finished task"
|
"[todoist_scrobble_task_finish] todoist webhook finish called on finished task"
|
||||||
)
|
)
|
||||||
|
return
|
||||||
|
|
||||||
scrobble.stop(force_finish=True)
|
scrobble.stop(force_finish=True)
|
||||||
|
|
||||||
|
|||||||
@ -67,7 +67,10 @@ def todoist_webhook(request):
|
|||||||
scrobble = todoist_scrobble_task(todoist_task, user_id)
|
scrobble = todoist_scrobble_task(todoist_task, user_id)
|
||||||
|
|
||||||
if not scrobble:
|
if not scrobble:
|
||||||
return Response({}, status=status.HTTP_400_BAD_REQUEST)
|
return Response(
|
||||||
|
{"error": "No scrobble found to be updated"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"[todoist_webhook] finished",
|
"[todoist_webhook] finished",
|
||||||
|
|||||||
Reference in New Issue
Block a user