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

Submit along Extra Info with jobs #53

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion client/ayon_deadline/abstract_submit_deadline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions client/ayon_deadline/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]":
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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, {})
Copy link
Member

Choose a reason for hiding this comment

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

Calling it directly job_info seems weird, I would prefer job_extra_info which is more descriptive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree!


# 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)}")