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 21 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
21 changes: 12 additions & 9 deletions services/processor/processor/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

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 +227,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 +246,8 @@ def start_processing(self):
self,
payload,
)

except Exception:
failed = True
self.log.error(
f"Unable to process handler {handler.__name__}",
exc_info=True
Expand All @@ -254,22 +256,23 @@ def start_processing(self):
event["id"],
status="failed",
description=(
"An error ocurred while processing"
"An error occurred while processing"
f"{event_id_text}"
),
payload={
"message": traceback.format_exc(),
},
)

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 asset AND finally entity_revival of Asset event
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 @@ -19,6 +19,7 @@
)

from utils import (
create_new_ayon_entity,
get_sg_entities,
get_asset_category,
update_ay_entity_custom_attributes,
Expand Down Expand Up @@ -115,7 +116,8 @@ def match_shotgrid_hierarchy_in_ayon(
)

if not ay_entity:
ay_entity = _create_new_entity(
ay_entity = create_new_ayon_entity(
sg_session,
entity_hub,
ay_parent_entity,
sg_ay_dict
Expand Down Expand Up @@ -227,74 +229,6 @@ def match_shotgrid_hierarchy_in_ayon(
)


def _create_new_entity(
entity_hub: ayon_api.entity_hub.EntityHub,
parent_entity: Union[ProjectEntity, FolderEntity],
sg_ay_dict: Dict
):
"""Helper method to create entities in the EntityHub.

Task Creation:
https://github.com/ynput/ayon-python-api/blob/30d702618b58676c3708f09f131a0974a92e1002/ayon_api/entity_hub.py#L284

Folder Creation:
https://github.com/ynput/ayon-python-api/blob/30d702618b58676c3708f09f131a0974a92e1002/ayon_api/entity_hub.py#L254


Args:
entity_hub (ayon_api.EntityHub): The project's entity hub.
parent_entity: AYON parent entity.
sg_ay_dict (dict): AYON ShotGrid entity to create.
"""
if sg_ay_dict["type"].lower() == "task":
# only create if parent_entity type is not project
if parent_entity.entity_type == "project":
log.warning(
f"Can't create task '{sg_ay_dict['name']}' under project "
"'{parent_entity.name}'. Parent should not be project it self!"
)
return

ay_entity = entity_hub.add_new_task(
sg_ay_dict["task_type"],
name=sg_ay_dict["name"],
label=sg_ay_dict["label"],
entity_id=sg_ay_dict["data"][CUST_FIELD_CODE_ID],
parent_id=parent_entity.id,
attribs=sg_ay_dict["attribs"],
data=sg_ay_dict["data"],
)
else:
ay_entity = entity_hub.add_new_folder(
sg_ay_dict["folder_type"],
name=sg_ay_dict["name"],
label=sg_ay_dict["label"],
entity_id=sg_ay_dict["data"][CUST_FIELD_CODE_ID],
parent_id=parent_entity.id,
attribs=sg_ay_dict["attribs"],
data=sg_ay_dict["data"],
)

# TODO: this doesn't work yet
status = sg_ay_dict["attribs"].get("status")
if status:
# TODO: Implement status update
try:
# INFO: it was causing error so trying to set status directly
ay_entity.status = status
except ValueError:
# `ValueError: Status ip is not available on project.`
# log.warning(f"Status sync not implemented: {e}")
pass

tags = sg_ay_dict["attribs"].get("tags")
if tags:
ay_entity.tags = [tag["name"] for tag in tags]

log.info(f"Created new entity: {ay_entity.name} ({ay_entity.id})")
return ay_entity


def _add_tags(project_name, tags):
"""Add tags to AYON project.

Expand Down
10 changes: 2 additions & 8 deletions services/shotgrid_common/ayon_shotgrid_hub/update_from_ayon.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,20 +253,14 @@ def remove_sg_entity_from_ayon_event(
sg_session (shotgun_api3.Shotgun): The Shotgrid API session.
"""
ay_id = ayon_event["payload"]["entityData"]["id"]
ay_entity_path = ayon_event["payload"]["entityData"].get("path")
log.debug(f"Removing Shotgrid entity: {ayon_event['payload']}")

if not ay_entity_path:
log.warning(
f"Entity '{ay_id}' does not have a path to remove from Shotgrid."
)
return

sg_id = ayon_event["payload"]["entityData"]["attrib"].get("shotgridId")

if not sg_id:
ay_entity_name = ayon_event["payload"]["entityData"]["name"]
kalisp marked this conversation as resolved.
Show resolved Hide resolved
log.warning(
f"Entity '{ay_entity_path}' does not have a "
f"Entity '{ay_entity_name}' does not have a "
"ShotGrid ID to remove."
)
return
Expand Down
Loading
Loading