Handle casting update events from Kitsu.
Process real-time casting update events from Kitsu (shot:casting-update or asset:casting-update). Fetch the current casting state from Kitsu, create a SyncCasting entity with the complete desired state, and push it to AYON for reconciliation.
NB: currently only supports shot casting updates. https://github.com/cgwire/zou/issues/392
Parameters:
| Name | Type | Description | Default |
parent | KitsuProcessor | KitsuProcessor instance with settings and project pairing info. | required |
data | dict[str, Any] | Event data dictionary from Kitsu containing: - project_id: Kitsu project ID One of the following is required: - shot_id: Shot ID for shot casting updates - asset_id: Asset ID for asset casting updates | required |
Returns:
| Type | Description |
None | None. The function logs warnings and returns early if: |
None | - Casting sync is disabled in settings
|
None | - Project is not paired with an AYON project
|
None | - Target entity cannot be determined
|
None | - Casting data cannot be fetched from Kitsu
|
Source code in services/processor/processor/update_from_kitsu.py
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438 | def create_or_update_casting(
parent: "KitsuProcessor", data: dict[str, Any]
) -> None:
"""Handle casting update events from Kitsu.
Process real-time casting update events from Kitsu (shot:casting-update
or asset:casting-update). Fetch the current casting state from Kitsu,
create a SyncCasting entity with the complete desired state, and push
it to AYON for reconciliation.
NB: currently only supports shot casting updates.
https://github.com/cgwire/zou/issues/392
Args:
parent: KitsuProcessor instance with settings and project pairing info.
data: Event data dictionary from Kitsu containing:
- project_id: Kitsu project ID
One of the following is required:
- shot_id: Shot ID for shot casting updates
- asset_id: Asset ID for asset casting updates
Returns:
None. The function logs warnings and returns early if:
- Casting sync is disabled in settings
- Project is not paired with an AYON project
- Target entity cannot be determined
- Casting data cannot be fetched from Kitsu
"""
logging.info(f"create_or_update_casting received event: {data}")
sync_casting_settings = (
parent.settings.get("sync_settings", {})
.get("sync_casting", {})
)
if not sync_casting_settings.get("enabled", False):
logging.debug("Casting sync is disabled, skipping")
return
project_name = parent.get_paired_ayon_project(data.get("project_id"))
if not project_name:
logging.debug(f"Project {data.get('project_id')} not paired, skipping")
return
# Kitsu sends different fields depending on the event type
# For shot:casting-update, Kitsu sends shot_id explicitly
target_id = None
if data.get("shot_id"):
target_id = data["shot_id"]
# For asset:casting-update, Kitsu sends asset_id explicitly
elif data.get("asset_id"):
target_id = data["asset_id"]
if not target_id:
logging.warning(f"Casting event missing target identifier: {data}")
return
try:
entity = gazu.entity.get_entity(target_id)
target_type = entity["type"]
logging.info(
f"Processing casting update for {target_type} {target_id}"
)
if target_type == "Shot":
casting = gazu.casting.get_shot_casting(entity)
elif target_type == "Asset":
casting = gazu.casting.get_asset_casting(entity)
else:
logging.warning(
f"Unable to fetch casting for {target_type.lower()} "
f"{target_id}: unsupported entity type {entity['type']}"
)
return
except Exception as e:
logging.warning(
f"Unable to fetch casting for {target_type.lower()} "
f"{target_id}: {e}"
)
return
# Extract asset_ids with occurence count
asset_ids: dict[str, int] = {}
for actor in casting:
actor_asset_id = actor.get("asset_id")
if actor_asset_id:
asset_ids[actor_asset_id] = asset_ids.get(
actor_asset_id, 0
) + actor.get("nb_occurences", 1)
# Create SyncCasting entity with complete state
entity = {
"id": f"sync-casting-{target_id}",
"type": "SyncCasting",
"target_id": target_id,
"target_type": target_type,
"asset_ids": asset_ids,
"project_id": data.get("project_id"),
"ayon_server_url": ayon_api.get_base_url(),
}
return ayon_api.post(
f"{parent.entrypoint}/push",
project_name=project_name,
entities=[entity],
)
|