Skip to content

submit_jobs_to_royalrender

Submit jobs to RoyalRender.

SubmitJobsToRoyalRender

Bases: ContextPlugin

Find all jobs, create submission XML and submit it to RoyalRender.

Source code in client/ayon_royalrender/plugins/publish/submit_jobs_to_royalrender.py
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 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
class SubmitJobsToRoyalRender(pyblish.api.ContextPlugin):
    """Find all jobs, create submission XML and submit it to RoyalRender."""
    label = "Submit jobs to RoyalRender"
    order = pyblish.api.IntegratorOrder + 0.3
    targets = ["local"]

    def __init__(self):
        super(SubmitJobsToRoyalRender, self).__init__()
        self._rr_root = None
        self._rr_api = None
        self._submission_parameters = []

    def process(self, context):

        # iterate over all instances and try to find RRJobs
        jobs = []
        auto_delete = False
        instance_rr_path = None
        for instance in context:
            if not instance.data.get("farm"):
                self.log.info("Skipping local instance.")
                continue
            if isinstance(instance.data.get("rrJob"), RRJob):
                jobs.append(instance.data.get("rrJob"))
            if instance.data.get("rrJobs"):
                if all(
                        isinstance(job, RRJob)
                        for job in instance.data.get("rrJobs")):
                    jobs += instance.data.get("rrJobs")
            if instance.data.get("rr_root"):
                instance_rr_path = instance.data["rr_root"]
            if instance.data.get("auto_delete"):
                #GlobalSubmissionParameter
                auto_delete=instance.data["auto_delete"]


        if jobs:
            self._rr_root = instance_rr_path
            if not self._rr_root:
                raise KnownPublishError(
                    ("Missing RoyalRender root. "
                     "You need to configure RoyalRender module."))
            self._rr_api = rrApi(self._rr_root)
            self._submission_parameters = self.get_submission_parameters(auto_delete)
            self.process_submission(jobs)
            return

        self.log.info("No RoyalRender jobs found")

    def process_submission(self, jobs):
        # type: ([RRJob]) -> None

        idx_pre_id = 0
        for job in jobs:
            job.PreID = idx_pre_id
            if idx_pre_id > 0:
                job.WaitForPreIDs.append(idx_pre_id - 1)
                # adjust rr pre id for publish job
                if job.SceneName.endswith("metadata.json"):
                    idx_pre_id =+ 10
            idx_pre_id += 1

        submission = rrApi.create_submission(
            jobs,
            self._submission_parameters)

        xml = tempfile.NamedTemporaryFile(suffix=".xml", delete=False)
        with open(xml.name, "w") as f:
            f.write(submission.serialize())

        self.log.info("submitting job(s) file: {}".format(xml.name))
        self._rr_api.submit_file(file=xml.name)

    def create_file(self, name, ext, contents=None):
        temp = tempfile.NamedTemporaryFile(
            dir=self.tempdir,
            suffix=ext,
            prefix=name + '.',
            delete=False,
        )

        if contents:
            with open(temp.name, 'w') as f:
                f.write(contents)

        return temp.name

    def get_submission_parameters(self, auto_delete):
        if auto_delete:
            return [
                SubmitterParameter("RequiredMemory", "0"),
                SubmitterParameter("PPAyoninjectenvvar", "1~1"),
                SubmitterParameter("-AutoDeleteEnabled")
            ]
        return [
            SubmitterParameter("RequiredMemory", "0"),
            SubmitterParameter("PPAyoninjectenvvar", "1~1")
        ]