diff --git a/client/ayon_deadline/abstract_submit_deadline.py b/client/ayon_deadline/abstract_submit_deadline.py index a02a0ce86e..54768d0dce 100644 --- a/client/ayon_deadline/abstract_submit_deadline.py +++ b/client/ayon_deadline/abstract_submit_deadline.py @@ -25,7 +25,11 @@ replace_with_published_scene_path ) -from .lib import get_ayon_render_job_envs, get_instance_job_envs +from .lib import ( + get_ayon_render_job_envs, + get_instance_job_envs, + get_instance_job_extra_info +) JSONDecodeError = getattr(json.decoder, "JSONDecodeError", ValueError) @@ -411,6 +415,12 @@ def add_instance_job_env_vars(self, instance): for key, value in get_instance_job_envs(instance).items(): self.EnvironmentKeyValue[key] = value + for key, value in get_instance_job_extra_info(instance).items(): + if isinstance(key, int): + self.ExtraInfo[key] = value + else: + self.ExtraInfoKeyValue[key] = value + @six.add_metaclass(AbstractMetaInstancePlugin) class AbstractSubmitDeadline(pyblish.api.InstancePlugin, diff --git a/client/ayon_deadline/lib.py b/client/ayon_deadline/lib.py index 75ad830a77..8593888b49 100644 --- a/client/ayon_deadline/lib.py +++ b/client/ayon_deadline/lib.py @@ -14,6 +14,7 @@ # Constant defining where we store job environment variables on instance or # context data JOB_ENV_DATA_KEY: str = "farmJobEnv" +JOB_EXTRA_INFO_DATA_KEY: str = "farmJobExtraInfo" def get_ayon_render_job_envs() -> "dict[str, str]": @@ -43,3 +44,23 @@ def get_instance_job_envs(instance) -> "dict[str, str]": env = dict(sorted(env.items())) return env + + +def get_instance_job_extra_info(instance) -> "dict[str | int, str]": + """Return the job extra info for the instance. + + Any instance extra info values will override the context extra info values. + """ + extra_info = {} + for job_extra_info in [ + instance.context.data.get(JOB_EXTRA_INFO_DATA_KEY, {}), + instance.data.get(JOB_EXTRA_INFO_DATA_KEY, {}) + ]: + if job_extra_info: + extra_info.update(job_extra_info) + + # Return the dict sorted just for readability in future logs + if extra_info: + extra_info = dict(sorted(extra_info.items())) + + return extra_info diff --git a/client/ayon_deadline/plugins/publish/global/collect_deadline_job_extra_info.py b/client/ayon_deadline/plugins/publish/global/collect_deadline_job_extra_info.py new file mode 100644 index 0000000000..0dc8e12940 --- /dev/null +++ b/client/ayon_deadline/plugins/publish/global/collect_deadline_job_extra_info.py @@ -0,0 +1,44 @@ +import json +import pyblish.api + +from ayon_deadline.lib import FARM_FAMILIES, JOB_EXTRA_INFO_DATA_KEY +from ayon_applications.utils import get_tools_for_context + + +class CollectDeadlineJobExtraInfo(pyblish.api.InstancePlugin): + """Collect set of environment variables to submit with deadline jobs""" + order = pyblish.api.CollectorOrder + 0.499 + label = "Deadline Farm Extra Info" + families = FARM_FAMILIES + targets = ["local"] + + def process(self, instance): + + # Transfer some environment variables from current context + job_info = instance.data.setdefault(JOB_EXTRA_INFO_DATA_KEY, {}) + + # Support Extra Info 0-10 (int key) + # Project Name, Folder Path, Task Name, App Name + context = instance.context + folder_entity = instance.data.get("folderEntity", {}) + + # TODO: Make this customizable in settings somehow? + job_info[0] = folder_entity.get("label") or folder_entity["name"] + job_info[1] = context.data.get("projectName", "") + job_info[2] = instance.data.get("folderPath", "") + job_info[3] = instance.data.get("task", "") + job_info[4] = instance.data.get("productName", "") + job_info[5] = instance.context.data.get("appName", "") + + # Supply the tools for the current context so that we can visualize + # on the farm what the tools were at time of submission + tools = get_tools_for_context( + project_name=context.data.get("projectName"), + folder_entity=context.data.get("folderEntity"), + task_entity=context.data.get("taskEntity"), + project_settings=context.data.get("project_settings") + ) + job_info[6] = " ".join(sorted(tools)) + + self.log.debug( + f"Farm job extra info: {json.dumps(job_info, indent=4)}")