[tasks] Don't stop tasks when modified while in progress
This commit is contained in:
@ -301,7 +301,10 @@ def todoist_scrobble_task_finish(
|
|||||||
todoist_task: dict, user_id: int
|
todoist_task: dict, user_id: int
|
||||||
) -> Optional[Scrobble]:
|
) -> 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"),
|
||||||
|
in_progress=True,
|
||||||
|
played_to_completion=False,
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if not scrobble:
|
if not scrobble:
|
||||||
@ -310,12 +313,6 @@ def todoist_scrobble_task_finish(
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not scrobble.in_progress or scrobble.played_to_completion:
|
|
||||||
logger.info(
|
|
||||||
"[todoist_scrobble_task_finish] todoist webhook finish called on finished task"
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
scrobble.stop(force_finish=True)
|
scrobble.stop(force_finish=True)
|
||||||
|
|
||||||
return scrobble
|
return scrobble
|
||||||
|
|||||||
@ -31,9 +31,19 @@ def todoist_webhook(request):
|
|||||||
event_data = post_data.get("event_data", {})
|
event_data = post_data.get("event_data", {})
|
||||||
is_item_type = todoist_type == "item"
|
is_item_type = todoist_type == "item"
|
||||||
is_note_type = todoist_type == "note"
|
is_note_type = todoist_type == "note"
|
||||||
|
new_labels = event_data.get("labels")
|
||||||
is_updated = todoist_event == ["updated"]
|
old_labels = (
|
||||||
is_added = todoist_event == ["added"]
|
post_data.get("event_data_extra", {})
|
||||||
|
.get("old_item", {})
|
||||||
|
.get("labels", [])
|
||||||
|
)
|
||||||
|
# TODO Don't hard code status strings in here
|
||||||
|
is_updated = (
|
||||||
|
todoist_event in ["updated"]
|
||||||
|
and "inprogress" in new_labels
|
||||||
|
and "inprogress" not in old_labels
|
||||||
|
)
|
||||||
|
is_added = todoist_event in ["added"]
|
||||||
|
|
||||||
if is_item_type:
|
if is_item_type:
|
||||||
todoist_task = {
|
todoist_task = {
|
||||||
@ -70,16 +80,26 @@ def todoist_webhook(request):
|
|||||||
)
|
)
|
||||||
return Response({}, status=status.HTTP_304_NOT_MODIFIED)
|
return Response({}, status=status.HTTP_304_NOT_MODIFIED)
|
||||||
|
|
||||||
|
if is_item_type and new_labels == old_labels:
|
||||||
|
logger.info(
|
||||||
|
"[todoist_webhook] ignoring item, labels unchanged",
|
||||||
|
extra={
|
||||||
|
"todoist_type": todoist_task["todoist_type"],
|
||||||
|
"todoist_event": todoist_task["todoist_event"],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return Response({}, status=status.HTTP_304_NOT_MODIFIED)
|
||||||
|
|
||||||
user_id = (
|
user_id = (
|
||||||
UserProfile.objects.filter(todoist_user_id=post_data.get("user_id"))
|
UserProfile.objects.filter(todoist_user_id=post_data.get("user_id"))
|
||||||
.first()
|
.first()
|
||||||
.user_id
|
.user_id
|
||||||
)
|
)
|
||||||
|
|
||||||
if todoist_task and todoist_event == "updated":
|
if todoist_task and is_updated:
|
||||||
scrobble = todoist_scrobble_task(todoist_task, user_id)
|
scrobble = todoist_scrobble_task(todoist_task, user_id)
|
||||||
|
|
||||||
if todoist_note and todoist_event == "added":
|
if todoist_note and is_added:
|
||||||
scrobble = todoist_scrobble_update_task(todoist_note, user_id)
|
scrobble = todoist_scrobble_update_task(todoist_note, user_id)
|
||||||
|
|
||||||
if not scrobble:
|
if not scrobble:
|
||||||
|
|||||||
Reference in New Issue
Block a user