Skip to content

Commit

Permalink
Merge pull request #144 from ynput/enhancement/ay-6234_sync-start-end…
Browse files Browse the repository at this point in the history
…-date

Sync: Sync start/end date and description
  • Loading branch information
iLLiCiTiT authored Oct 4, 2024
2 parents bf93ba8 + 207f39b commit 3a5cc41
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,21 @@

UNKNOWN_VALUE = object()

DEFAULT_ATTRS_MAPPING = {
"startdate": "startDate",
"enddate": "endDate",
"description": "description",
}


class SyncProcess:
interest_base_types = ["show", "task"]
ignore_ent_types = ["Milestone"]
ignore_change_keys = ["statusid", "thumbid"]
ignore_change_keys = [
"statusid",
"thumbid",
"priorityid",
]

project_query = (
"select id, full_name, name, custom_attributes,"
Expand Down Expand Up @@ -1320,13 +1330,27 @@ def _propagate_attrib_changes(self):
if key == "typeid" and entity.entity_type == "task":
task_type_changes[ftrack_id] = (entity, info)

dst_key = key
if key == CUST_ATTR_TOOLS:
default_attr_key = DEFAULT_ATTRS_MAPPING.get(key)

if default_attr_key is not None:
dst_key = default_attr_key
elif key == CUST_ATTR_TOOLS:
dst_key = "tools"
else:
dst_key = key

if dst_key not in entity.attribs:
continue

if value is not None:
if default_attr_key is not None:
if value is not None and key in ("startdate", "enddate"):
date = arrow.get(value)
# Shift date to 00:00:00 of the day
# - ftrack is returning e.g. '2024-10-29T22:00:00'
# for '2024-10-30'
value = str(date.shift(hours=24 - date.hour))

elif value is not None:
if key in FPS_KEYS:
value = convert_to_fps(value)
else:
Expand All @@ -1337,6 +1361,7 @@ def _propagate_attrib_changes(self):
continue
value = self._convert_value_by_cust_attr_conf(
value, attr)

entity.attribs[dst_key] = value

self._propagate_task_type_changes(task_type_changes)
Expand Down
21 changes: 20 additions & 1 deletion services/processor/processor/lib/sync_from_ftrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
import logging

import arrow
from ayon_api import (
get_project,
create_project,
Expand Down Expand Up @@ -308,7 +309,8 @@ def sync_to_server(self):

self.log.info("Querying project hierarchy from ftrack")
ft_entities = ft_session.query((
"select id, name, parent_id, type_id, object_type_id"
"select id, name, parent_id, type_id, object_type_id, status_id"
", start_date, end_date, description" #, bid, status_id"
" from TypedContext where project_id is \"{}\""
).format(ft_project["id"])).all()
t_ft_entities_4 = time.perf_counter()
Expand Down Expand Up @@ -707,6 +709,23 @@ def update_attributes_from_ftrack(
])
entity.attribs[FTRACK_ID_ATTRIB] = ftrack_id
entity.attribs[FTRACK_PATH_ATTRIB] = path

for attr_name, value in (
("startDate", ft_entity["start_date"]),
("endDate", ft_entity["end_date"]),
("description", ft_entity.get("description")),
):
if value is None or attr_name not in entity.attribs:
continue

if isinstance(value, arrow.Arrow):
# Shift date to 00:00:00 of the day
# - ftrack is returning e.g. '2024-10-29T22:00:00'
# for '2024-10-30'
value = str(value.shift(hours=24 - value.hour))

entity.attribs[attr_name] = str(value)

# ftrack id can not be available if ftrack entity was recreated
# during immutable entity processing
attribute_values = cust_attr_value_by_entity_id[ftrack_id]
Expand Down

0 comments on commit 3a5cc41

Please sign in to comment.