Skip to content

create_publish_royalrender_job

Create publishing job on RoyalRender.

CreatePublishRoyalRenderJob

Bases: InstancePlugin, ColormanagedPyblishPluginMixin

Creates job which publishes rendered files to publish area.

Job waits until all rendering jobs are finished, triggers publish command where it reads from prepared .json file with metadata about what should be published, renames prepared images and publishes them.

When triggered it produces .log file next to .json file in work area.

Source code in client/ayon_royalrender/plugins/publish/create_publish_royalrender_job.py
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
class CreatePublishRoyalRenderJob(pyblish.api.InstancePlugin,
                                  publish.ColormanagedPyblishPluginMixin):
    """Creates job which publishes rendered files to publish area.

    Job waits until all rendering jobs are finished, triggers `publish` command
    where it reads from prepared .json file with metadata about what should
    be published, renames prepared images and publishes them.

    When triggered it produces .log file next to .json file in work area.
    """
    label = "Create publish job in RR"
    order = pyblish.api.IntegratorOrder + 0.2
    icon = "tractor"
    targets = ["local"]
    hosts = ["fusion", "maya", "nuke", "celaction", "aftereffects", "harmony"]
    families = ["render.farm", "prerender.farm", "render.frames_farm",
                "renderlayer", "imagesequence", "vrayscene"]
    aov_filter = {"maya": [r".*([Bb]eauty).*"],
                  "aftereffects": [r".*"],  # for everything from AE
                  "harmony": [r".*"],  # for everything from AE
                  "celaction": [r".*"]}

    skip_integration_repre_list = []

    # mapping of instance properties to be transferred to new instance
    #     for every specified family
    instance_transfer = {
        "slate": ["slateFrames", "slate"],
        "review": ["lutPath"],
        "render2d": ["bakingNukeScripts", "version"],
        "renderlayer": ["convertToScanline"]
    }

    # list of family names to transfer to new family if present
    families_transfer = ["render3d", "render2d", "ftrack", "slate"]

    environ_keys = [
        "FTRACK_API_USER",
        "FTRACK_API_KEY",
        "FTRACK_SERVER",
        "AYON_APP_NAME",
        "AYON_USERNAME",
        "AYON_SG_USERNAME",
        'AYON_API_KEY',
        'AYON_SERVER_URL',
        'AYON_VERSION',
        'USE_AYON_SERVER',
        'AYON_DEFAULT_SETTINGS_VARIANT',
        'AYON_BUNDLE_NAME',
        'AYON_SITE_ID',
        'PYTHONPATH',
        'AYON_ROOT',
        'AYON_MENU_LABEL'
        ]


    priority = 50

    def process(self, instance):
        context = instance.context
        self.context = context
        self.anatomy = instance.context.data["anatomy"]

        if not instance.data.get("farm") or instance.data.get("frames_farm"):
            self.log.info("Skipping local instance.")
            return

        instance_skeleton_data = create_skeleton_instance(
            instance,
            families_transfer=self.families_transfer,
            instance_transfer=self.instance_transfer)

        do_not_add_review = False
        if instance.data.get("review") is False:
            self.log.debug("Instance has review explicitly disabled.")
            do_not_add_review = True

        if isinstance(instance.data.get("expectedFiles")[0], dict):
            instances = create_instances_for_aov(
                instance, instance_skeleton_data,
                self.aov_filter, self.skip_integration_repre_list,
                do_not_add_review)

        else:
            representations = prepare_representations(
                instance_skeleton_data,
                instance.data.get("expectedFiles"),
                self.anatomy,
                self.aov_filter,
                self.skip_integration_repre_list,
                do_not_add_review,
                instance.context,
                self
            )

            if "representations" not in instance_skeleton_data.keys():
                instance_skeleton_data["representations"] = []

            # add representation
            instance_skeleton_data["representations"] += representations
            instances = [instance_skeleton_data]

        # attach instances to product
        if instance.data.get("attachTo"):
            instances = attach_instances_to_product(
                instance.data.get("attachTo"), instances
            )

        self.log.info("Creating RoyalRender Publish job ...")

        if not instance.data.get("rrJobs"):
            self.log.error(("There is no prior RoyalRender "
                            "job on the instance."))
            raise KnownPublishError(
                "Can't create publish job without prior rendering jobs first")

        rr_job = self.get_job(instance, instances)
        instance.data["rrJobs"].append(rr_job)

        # publish job file
        publish_job = {
            "folderPath": instance_skeleton_data["folderPath"],
            "frameStart": instance_skeleton_data["frameStart"],
            "frameEnd": instance_skeleton_data["frameEnd"],
            "fps": instance_skeleton_data["fps"],
            "source": instance_skeleton_data["source"],
            "user": instance.context.data["user"],
            "version": instance.context.data["version"],   # workfile version
            "intent": instance.context.data.get("intent"),
            "comment": instance.context.data.get("comment"),
            "job": attr.asdict(rr_job),
            "instances": instances
        }

        metadata_path, rootless_metadata_path = \
            create_metadata_path(instance, self.anatomy)

        self.log.info("Writing json file: {}".format(metadata_path))

        #convert submitter parameters to str as preparation for
        #json dump - needs improvement
        publish_job["job"]["SubmitterParameters"] = str(publish_job["job"]["SubmitterParameters"])


        with open(metadata_path, "w") as f:
            json.dump(publish_job, f, indent=4, sort_keys=True)

    def get_job(self, instance, instances):
        """Create RR publishing job.

        Based on provided original instance and additional instances,
        create publishing job and return it to be submitted to farm.

        Args:
            instance (Instance): Original instance.
            instances (list of Instance): List of instances to
                be published on farm.

        Returns:
            RRJob: RoyalRender publish job.

        """
        data = instance.data.copy()
        product_name = data["productName"]
        jobname = "Publish - {}".format(product_name)

        # Transfer the environment from the original job to this dependent
        # job, so they use the same environment
        metadata_path, rootless_metadata_path = \
            create_metadata_path(instance, self.anatomy)

        anatomy_data = instance.context.data["anatomyData"]

        environment = RREnvList({
            "AYON_PROJECT_NAME": anatomy_data["project"]["name"],
            "AYON_FOLDER_PATH": instance.context.data["folderPath"],
            "AYON_TASK_NAME": anatomy_data["task"]["name"],
            "AYON_USERNAME": anatomy_data["user"]
        })

        # add environments from self.environ_keys
        for env_key in self.environ_keys:
            if os.getenv(env_key):
                environment[env_key] = os.environ[env_key]

        # pass environment keys from self.environ_job_filter
        # and collect all pre_ids to wait for
        job_environ = {}
        jobs_pre_ids = []
        for job in instance.data["rrJobs"]:  # type: RRJob
            if job.rrEnvList:
                if len(job.rrEnvList) > 2000:
                    self.log.warning(("Job environment is too long "
                                      f"{len(job.rrEnvList)} > 2000"))
                job_environ.update(
                    dict(RREnvList.parse(job.rrEnvList))
                )
            jobs_pre_ids.append(job.PreID)

        priority = self.priority or instance.data.get("priority", 50)
        suspend_publish = instance.data.get("suspend_publish", False)

        submitter_parameters_job = [
            SubmitterParameter("SendJobDisabled",
                               "1",
                               f"{suspend_publish}"),
            SubmitterParameter("Priority",
                               "1",
                               f"{priority}")
        ]

        # rr requires absolut path or all jobs won't show up in rControl
        abs_metadata_path = self.anatomy.fill_root(rootless_metadata_path)

        # additional logging
        args = [
            ">", os.path.join(os.path.dirname(abs_metadata_path),
                              "rr_out.log"),
            "2>&1"
        ]

        job = RRJob(
            Software="AYON",
            Renderer="Once",
            SeqStart=1,
            SeqEnd=1,
            SeqStep=1,
            SeqFileOffset=0,
            Version=os.environ["AYON_BUNDLE_NAME"],
            SceneName=abs_metadata_path,
            # command line arguments
            CustomAddCmdFlags=" ".join(args),
            IsActive=True,
            ImageFilename="execOnce.file",
            ImageDir="<SceneFolder>",
            ImageExtension="",
            ImagePreNumberLetter="",
            SceneOS=get_rr_platform(),
            rrEnvList=environment.serialize(),
            CustomSHotName=jobname,
            CompanyProjectName=instance.context.data["projectName"],
            SubmitterParameters=submitter_parameters_job
        )

        # add assembly jobs as dependencies
        if instance.data.get("tileRendering"):
            self.log.info("Adding tile assembly jobs as dependencies...")
            job.WaitForPreIDs += instance.data.get("assemblySubmissionJobs")
        elif instance.data.get("bakingSubmissionJobs"):
            self.log.info("Adding baking submission jobs as dependencies...")
            job.WaitForPreIDs += instance.data["bakingSubmissionJobs"]
        else:
            job.WaitForPreIDs += jobs_pre_ids

        return job

get_job(instance, instances)

Create RR publishing job.

Based on provided original instance and additional instances, create publishing job and return it to be submitted to farm.

Parameters:

Name Type Description Default
instance Instance

Original instance.

required
instances list of Instance

List of instances to be published on farm.

required

Returns:

Name Type Description
RRJob

RoyalRender publish job.

Source code in client/ayon_royalrender/plugins/publish/create_publish_royalrender_job.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
def get_job(self, instance, instances):
    """Create RR publishing job.

    Based on provided original instance and additional instances,
    create publishing job and return it to be submitted to farm.

    Args:
        instance (Instance): Original instance.
        instances (list of Instance): List of instances to
            be published on farm.

    Returns:
        RRJob: RoyalRender publish job.

    """
    data = instance.data.copy()
    product_name = data["productName"]
    jobname = "Publish - {}".format(product_name)

    # Transfer the environment from the original job to this dependent
    # job, so they use the same environment
    metadata_path, rootless_metadata_path = \
        create_metadata_path(instance, self.anatomy)

    anatomy_data = instance.context.data["anatomyData"]

    environment = RREnvList({
        "AYON_PROJECT_NAME": anatomy_data["project"]["name"],
        "AYON_FOLDER_PATH": instance.context.data["folderPath"],
        "AYON_TASK_NAME": anatomy_data["task"]["name"],
        "AYON_USERNAME": anatomy_data["user"]
    })

    # add environments from self.environ_keys
    for env_key in self.environ_keys:
        if os.getenv(env_key):
            environment[env_key] = os.environ[env_key]

    # pass environment keys from self.environ_job_filter
    # and collect all pre_ids to wait for
    job_environ = {}
    jobs_pre_ids = []
    for job in instance.data["rrJobs"]:  # type: RRJob
        if job.rrEnvList:
            if len(job.rrEnvList) > 2000:
                self.log.warning(("Job environment is too long "
                                  f"{len(job.rrEnvList)} > 2000"))
            job_environ.update(
                dict(RREnvList.parse(job.rrEnvList))
            )
        jobs_pre_ids.append(job.PreID)

    priority = self.priority or instance.data.get("priority", 50)
    suspend_publish = instance.data.get("suspend_publish", False)

    submitter_parameters_job = [
        SubmitterParameter("SendJobDisabled",
                           "1",
                           f"{suspend_publish}"),
        SubmitterParameter("Priority",
                           "1",
                           f"{priority}")
    ]

    # rr requires absolut path or all jobs won't show up in rControl
    abs_metadata_path = self.anatomy.fill_root(rootless_metadata_path)

    # additional logging
    args = [
        ">", os.path.join(os.path.dirname(abs_metadata_path),
                          "rr_out.log"),
        "2>&1"
    ]

    job = RRJob(
        Software="AYON",
        Renderer="Once",
        SeqStart=1,
        SeqEnd=1,
        SeqStep=1,
        SeqFileOffset=0,
        Version=os.environ["AYON_BUNDLE_NAME"],
        SceneName=abs_metadata_path,
        # command line arguments
        CustomAddCmdFlags=" ".join(args),
        IsActive=True,
        ImageFilename="execOnce.file",
        ImageDir="<SceneFolder>",
        ImageExtension="",
        ImagePreNumberLetter="",
        SceneOS=get_rr_platform(),
        rrEnvList=environment.serialize(),
        CustomSHotName=jobname,
        CompanyProjectName=instance.context.data["projectName"],
        SubmitterParameters=submitter_parameters_job
    )

    # add assembly jobs as dependencies
    if instance.data.get("tileRendering"):
        self.log.info("Adding tile assembly jobs as dependencies...")
        job.WaitForPreIDs += instance.data.get("assemblySubmissionJobs")
    elif instance.data.get("bakingSubmissionJobs"):
        self.log.info("Adding baking submission jobs as dependencies...")
        job.WaitForPreIDs += instance.data["bakingSubmissionJobs"]
    else:
        job.WaitForPreIDs += jobs_pre_ids

    return job