Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shotgrid: reviving archived assets is broken #122

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
76d21f0
Changed type of task revival event
kalisp Aug 13, 2024
5d9213f
Added MissingParentError to processor
kalisp Aug 13, 2024
6e70e33
Updated query of last event
kalisp Aug 13, 2024
c4e8015
Merge branch 'develop' of https://github.com/ynput/ayon-shotgrid into…
kalisp Aug 14, 2024
26c9e53
Cleaned up logic
kalisp Aug 16, 2024
5163b29
Formatting
kalisp Aug 19, 2024
3fcac8f
Formatting change
kalisp Aug 19, 2024
8fd3c90
Cosmetics fix
kalisp Sep 10, 2024
05e2339
Cosmetics fix
kalisp Sep 10, 2024
a08c442
Fix typo
kalisp Sep 10, 2024
638105c
Fix typo
kalisp Sep 10, 2024
4b65500
Merge branch 'develop' of https://github.com/ynput/ayon-shotgrid into…
kalisp Sep 11, 2024
5b857ec
Merge remote-tracking branch 'origin/enhancement/AY-5570_shotgrid-rev…
kalisp Sep 11, 2024
b531fb1
Fix log message
kalisp Sep 11, 2024
d23b80a
Refactor to more readable variable
kalisp Sep 11, 2024
66761a9
Fix creation of task directly under project
kalisp Sep 11, 2024
0d85a5f
Fix remove nonexistent key
kalisp Sep 12, 2024
a674780
Fix typo
kalisp Sep 12, 2024
c449b04
Merge develop
kalisp Oct 10, 2024
b6985bc
Refactor yank out create_new_ayon_entity
kalisp Oct 11, 2024
4c2f5f5
Reworked revival from MissingParentError to parent creation
kalisp Oct 14, 2024
a0eaeaa
Formatting change
kalisp Nov 12, 2024
ba4849c
Merge branch 'develop' of https://github.com/ynput/ayon-shotgrid into…
kalisp Nov 12, 2024
fe9d09f
Merge remote-tracking branch 'origin/enhancement/AY-5570_shotgrid-rev…
kalisp Nov 12, 2024
2ff9b42
Updated docstring
kalisp Nov 12, 2024
0da0e9e
Updated logging
kalisp Nov 12, 2024
af426a9
Return path for logging
kalisp Nov 12, 2024
af870c9
Update logging
kalisp Nov 12, 2024
759bd0a
Fix logic to change only real Task revival
kalisp Nov 12, 2024
72f1393
Removed filtering on tasks
kalisp Nov 12, 2024
1281ba1
Fix ruff
kalisp Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 51 additions & 9 deletions services/processor/processor/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import ayon_api
import shotgun_api3

from utils import get_logger
from utils import get_logger, get_event_hash

from constants import MissingParentError

class ShotgridProcessor:
_sg: shotgun_api3.Shotgun = None
_RETRIGGERED_TOPIC = "shotgrid.event.retriggered"
log = get_logger(__file__)

def __init__(self):
Expand Down Expand Up @@ -226,6 +228,7 @@ def start_processing(self):
)
continue

failed = False
for handler in self.handlers_map.get(payload["action"], []):
# If theres any handler "subscribed" to this event type..
try:
Expand All @@ -244,8 +247,46 @@ def start_processing(self):
self,
payload,
)

except MissingParentError:
Copy link
Member

@iLLiCiTiT iLLiCiTiT Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we can't recreate parents instead of retriggering the event? Processor should not trigger events, it will add the event to the end of queue which might lead to huge issues as the task might change meanwhile, but you'll reapply changes from older event.

If this https://github.com/ynput/ayon-shotgrid/pull/122/files#r1718231580 happens because of this, then that is another reason against.

BTW is possible missing parent can happen even if it was not "reactivated"? Can it happen if the parents couldn't be synced (e.g. invalid chars of some other issue)?

failed = True
ayon_api.update_event(
event["id"],
status="failed",
description=(
"An error ocurred while processing"
f"{event_id_text}, will be retried"
kalisp marked this conversation as resolved.
Show resolved Hide resolved
),
payload={
"message": traceback.format_exc(),
},
retries=999
)
if source_event["topic"] != self._RETRIGGERED_TOPIC:
self.log.error(
f"Reprocess handler {handler.__name__}, "
"will be retried in new order",
)

# to limit primary key violation
new_event_hash = get_event_hash(
self._RETRIGGERED_TOPIC,
f"{payload['sg_payload']['id']}_dummy"
)
desc = (source_event['description'].
replace("Leeched", "Recreated"))
ayon_api.dispatch_event(
self._RETRIGGERED_TOPIC,
sender=socket.gethostname(),
payload=payload,
summary=summary,
description=desc,
event_hash=new_event_hash
)
else:
self.log.warning("Source event already failed, "
"won't be retried again.")
except Exception:
failed = True
self.log.error(
f"Unable to process handler {handler.__name__}",
exc_info=True
Expand All @@ -262,14 +303,15 @@ def start_processing(self):
},
)

self.log.info(
"Event has been processed... setting to finished!")
if not failed:
self.log.info(
"Event has been processed... setting to finished!")

ayon_api.update_event(
event["id"],
description=f"Event processed successfully{event_id_text}",
status="finished",
)
ayon_api.update_event(
event["id"],
description=f"Event processed successfully{event_id_text}",
status="finished",
)

except Exception:
self.log.error(traceback.format_exc())
Expand Down
10 changes: 10 additions & 0 deletions services/shotgrid_common/ayon_shotgrid_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,16 @@ def react_to_shotgrid_event(self, sg_event_meta):
f"Ignoring event, AYON project {self.project_name} not found.")
return

# task revived only sends attribute_change event, before attribute
# change of parent assent AND finally entity_revival of Asset event
kalisp marked this conversation as resolved.
Show resolved Hide resolved
if (sg_event_meta["type"] == "attribute_change"
and sg_event_meta["attribute_name"] == "retirement_date"):
if sg_event_meta["entity_type"].lower() != "task":
kalisp marked this conversation as resolved.
Show resolved Hide resolved
# do nothing for update retirement_date on non existing Asset
return
self.log.info("changed to entity_revival")
kalisp marked this conversation as resolved.
Show resolved Hide resolved
sg_event_meta["type"] = "entity_revival"

match sg_event_meta["type"]:
case "new_entity" | "entity_revival":
self.log.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
SHOTGRID_TYPE_ATTRIB, # Ayon Entity Attribute.
SHOTGRID_REMOVED_VALUE, # Value for removed entities.
SG_RESTRICTED_ATTR_FIELDS,
MissingParentError
)

from utils import get_logger
Expand Down Expand Up @@ -172,8 +173,9 @@ def create_ay_entity_from_sg_event(
if not ay_parent_entity:
# This really should be an edge ase, since any parent event would
# happen before this... but hey
raise ValueError(
"Parent does not exist in Ayon, try doing a Project Sync.")
raise MissingParentError(
"Parent does not exist in Ayon, this event will be retried"
"after while. Hopefully parent will be already created.")
kalisp marked this conversation as resolved.
Show resolved Hide resolved

if sg_ay_dict["type"].lower() == "task":
ay_entity = ayon_entity_hub.add_new_task(
Expand Down Expand Up @@ -284,7 +286,7 @@ def update_ayon_entity_from_sg_event(
)

if not ay_entity:
raise ValueError("Unable to update a non existing entity.")
raise MissingParentError("Unable to update a non existing entity.")
kalisp marked this conversation as resolved.
Show resolved Hide resolved

# make sure the entity is not immutable
if (
Expand Down
19 changes: 19 additions & 0 deletions services/shotgrid_common/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,22 @@
"session_uuid",
"created_at",
]


class MissingParentError(Exception):
"""This error could depend on order of processing.

Logic should capture this exception and dispatch source event again for
reprocessing. Source event couldn't be only failed as it would keep same
order. New event will be placed at the end of the queue.

This exception should be only raised if parent of the created/updated
object doesn't exist yet.

(Use case - task should be updated, but its parent Asset doesn't exist
yet.)

Source event payload should contain some additional key (like
`already_retried` that would protect from infinitive retries.
"""
pass