Ejemplo n.º 1
0
    def job_run(self, job):
        """Create and queue tasks from job object"""

        # job_id from db is be used as session name
        self.ip_client.session.session = str(job['_id'])

        # set owner of job
        self.ip_client.session.username = job['owner']

        # set number of retries for each task
        self.lbview.retries = job['retries']

        # depend on another job (it's tasks)
        if ('depend' in job['limits']) and (job['limits']['depend'] != None):
            depend_job = self.query_job_by_name(job['limits']['depend'])
            depend_tasks = self.query_task_list(depend_job['_id'])
            task_ids = []
            for task in depend_tasks:
                task_ids.append(task['msg_id'])
            self.lbview.after = task_ids


        task_frames = list(range(job['startframe'], job['endframe'] + 1, job['blocksize']))
        ar = None
        for x in task_frames:

            # prepare script input
            env_dict = {
            'DRQUEUE_FRAME' : x,
            'DRQUEUE_BLOCKSIZE' : job['blocksize'],
            'DRQUEUE_ENDFRAME' : job['endframe'],
            'DRQUEUE_SCENEFILE' : job['scenefile']
            }

            # log filename
            if job['created_with'] == "DrQueueOnRails":
                # take job directory name
                env_dict['DRQUEUE_LOGFILE'] = job['scenefile'].split("/")[-2] + "-" + str(x) + "_" + str(x + job['blocksize'] -1) + ".log"
            else:
                # take job name
                env_dict['DRQUEUE_LOGFILE'] = job['name'] + "-" + str(x) + "_" + str(x + job['blocksize'] -1) + ".log"

            # optional elements
            if 'renderdir' in job:
                env_dict['DRQUEUE_RENDERDIR'] = job['renderdir']
            if 'projectdir' in job:
                env_dict['DRQUEUE_PROJECTDIR'] = job['projectdir']
            if 'configdir' in job:
                env_dict['DRQUEUE_CONFIGDIR'] = job['configdir']
            if 'imagefile' in job:
                env_dict['DRQUEUE_IMAGEFILE'] = job['imagefile']
            if 'precommand' in job:
                env_dict['DRQUEUE_PRECOMMAND'] = job['precommand']
            if 'renderer' in job:
                env_dict['DRQUEUE_RENDERER'] = job['renderer']
            if 'fileformat' in job:
                env_dict['DRQUEUE_FILEFORMAT'] = job['fileformat']
            if 'postcommand' in job:
                env_dict['DRQUEUE_POSTCOMMAND'] = job['postcommand']
            if 'viewcommand' in job:
                env_dict['DRQUEUE_VIEWCOMMAND'] = job['viewcommand']
            if 'worldfile' in job:
                env_dict['DRQUEUE_WORLDFILE'] = job['worldfile']
            if 'terrainfile' in job:
                env_dict['DRQUEUE_TERRAINFILE'] = job['terrainfile']
            if 'composition' in job:
                env_dict['DRQUEUE_COMPOSITION'] = job['composition']
            if 'camera' in job:
                env_dict['DRQUEUE_CAMERA'] = job['camera']
            if 'resx' in job:
                env_dict['DRQUEUE_RESX'] = job['resx']
            if 'resy' in job:
                env_dict['DRQUEUE_RESY'] = job['resy']
            if 'renderpass' in job:
                env_dict['DRQUEUE_RENDERPASS'] = job['renderpass']
            if 'rendertype' in job:
                env_dict['DRQUEUE_RENDERTYPE'] = job['rendertype']
            if 'fileextension' in job:
                env_dict['DRQUEUE_FILEEXTENSION'] = job['fileextension']
            if 'stepframe' in job:
                env_dict['DRQUEUE_STEPFRAME'] = job['stepframe']
            if 'custom_bucket' in job:
                env_dict['DRQUEUE_CUSTOM_BUCKET'] = job['custom_bucket']
            if 'bucketsize' in job:
                env_dict['DRQUEUE_BUCKETSIZE'] = job['bucketsize']
            if 'custom_lod' in job:
                env_dict['DRQUEUE_CUSTOM_LOD'] = job['custom_lod']
            if 'lod' in job:
                env_dict['DRQUEUE_LOD'] = job['lod']
            if 'custom_varyaa' in job:
                env_dict['DRQUEUE_CUSTOM_VARYAA'] = job['custom_varyaa']
            if 'varyaa' in job:
                env_dict['DRQUEUE_VARYAA'] = job['varyaa']
            if 'raytrace' in job:
                env_dict['DRQUEUE_RAYTRACE'] = job['raytrace']
            if 'antialias' in job:
                env_dict['DRQUEUE_ANTIALIAS'] = job['antialias']
            if 'custom_bdepth' in job:
                env_dict['DRQUEUE_CUSTOM_BDEPTH'] = job['custom_bdepth']
            if 'bdepth' in job:
                env_dict['DRQUEUE_BDEPTH'] = job['bdepth']
            if 'custom_zdepth' in job:
                env_dict['DRQUEUE_CUSTOM_ZDEPTH'] = job['custom_zdepth']
            if 'zdepth' in job:
                env_dict['DRQUEUE_ZDEPTH'] = job['zdepth']
            if 'custom_cracks' in job:
                env_dict['DRQUEUE_CUSTOM_CRACKS'] = job['custom_cracks']
            if 'cracks' in job:
                env_dict['DRQUEUE_CRACKS'] = job['cracks']
            if 'custom_quality' in job:
                env_dict['DRQUEUE_CUSTOM_QUALITY'] = job['custom_quality']
            if 'quality' in job:
                env_dict['DRQUEUE_QUALITY'] = job['quality']
            if 'custom_qfiner' in job:
                env_dict['DRQUEUE_CUSTOM_QFINER'] = job['custom_qfiner']
            if 'qfiner' in job:
                env_dict['DRQUEUE_QFINER'] = job['qfiner']
            if 'custom_smultiplier' in job:
                env_dict['DRQUEUE_CUSTOM_SMULTIPLIER'] = job['custom_smultiplier']
            if 'smultiplier' in job:
                env_dict['DRQUEUE_SMULTIPLIER'] = job['smultiplier']
            if 'custom_mpcache' in job:
                env_dict['DRQUEUE_CUSTOM_MPCACHE'] = job['custom_mpcache']
            if 'mpcache' in job:
                env_dict['DRQUEUE_MPCACHE'] = job['mpcache']
            if 'custom_smpolygon' in job:
                env_dict['DRQUEUE_CUSTOM_SMPOLYGON'] = job['custom_smpolygon']
            if 'smpolygon' in job:
                env_dict['DRQUEUE_SMPOLYGON'] = job['smpolygon']
            if 'custom_wh' in job:
                env_dict['DRQUEUE_CUSTOM_WH'] = job['custom_wh']
            if 'custom_type' in job:
                env_dict['DRQUEUE_CUSTOM_TYPE'] = job['custom_type']
            if 'ctype' in job:
                env_dict['DRQUEUE_CTYPE'] = job['ctype']
            if 'skipframes' in job:
                env_dict['DRQUEUE_SKIPFRAMES'] = job['skipframes']
            if 'custom_command' in job:
                env_dict['DRQUEUE_CUSTOM_COMMAND'] = job['custom_command']

            # set dependencies
            dep_dict = {}
            dep_dict['job_id'] = str(job['_id'])
            if ('os' in job['limits']) and (job['limits']['os'] != None):
                dep_dict['os_name'] = job['limits']['os']
            if ('minram' in job['limits']) and (job['limits']['minram'] > 0):
                dep_dict['minram'] = job['limits']['minram']
            if ('mincores' in job['limits']) and (job['limits']['mincores'] > 0):
                dep_dict['mincores'] = job['limits']['mincores']
            if ('pool_name' in job['limits']) and (job['limits']['pool_name'] != None):
                dep_dict['pool_name'] = job['limits']['pool_name']
            run_script_with_env_and_deps = dependent(DrQueue.run_script_with_env, DrQueue.check_deps, dep_dict)

            # run task on cluster
            render_script = DrQueue.get_rendertemplate(job['renderer'])
            ar = self.lbview.apply(run_script_with_env_and_deps, render_script, env_dict)
            # wait for pyzmq send to complete communication (avoid race condition)
            ar.wait_for_send()

        # append email task behind last task if requested
        if ('send_email' in job) and (job['send_email'] == True):
            self.lbview.after = ar
            # run email task
            mail_ar = self.lbview.apply(DrQueue.send_email, job['name'], job['email_recipients'])
            # wait for pyzmq send to complete communication (avoid race condition)
            mail_ar.wait_for_send()
        return True
Ejemplo n.º 2
0
    def __init__(self, name, startframe, endframe, blocksize, renderer, scenefile, retries=1, owner=getpass.getuser(), options={}, limits={}):
        dict.__init__(self)
        # mandatory elements
        jb = {'name' : name,
              'startframe' : startframe,
              'endframe' : endframe,
              'blocksize' : blocksize,
              'renderer' : renderer,
              'scenefile' : scenefile,
              'retries' : retries,
              'owner' : owner,
              'limits' : {}
             }
        if name == "":
            raise ValueError("No name of job given!")
            return False
        if not (endframe >= startframe >= 1):
            raise ValueError("Startframe and endframe need to be at least 1!")
            return False
        if blocksize < 1:
            raise ValueError("Blocksize needs to be at least 1!")
            return False
        if DrQueue.check_renderer_support(renderer) == False:
            raise ValueError("Render called \"%s\" not supported!" % renderer)
            return False
        if scenefile == "":
            raise ValueError("No scenefile given!")
            return False
        # optional elements
        if 'renderdir' in options:
            jb['renderdir'] = options['renderdir']
        if 'projectdir' in options:
            jb['projectdir'] = options['projectdir']
        if 'configdir' in options:
            jb['configdir'] = options['configdir']
        if 'imagefile' in options:
            jb['imagefile'] = options['imagefile']
        if 'precommand' in options:
            jb['precommand'] = options['precommand']
        if 'postcommand' in options:
            jb['postcommand'] = options['postcommand']
        if 'viewcommand' in options:
            jb['viewcommand'] = options['viewcommand']
        if 'worldfile' in options:
            jb['worldfile'] = options['worldfile']
        if 'terrainfile' in options:
            jb['terrainfile'] = options['terrainfile']
        if 'composition' in options:
            jb['composition'] = options['composition']
        if 'camera' in options:
            jb['camera'] = options['camera']
        if 'resx' in options:
            jb['resx'] = options['resx']
        if 'resy' in options:
            jb['resy'] = options['resy']
        if 'renderpass' in options:
            jb['renderpass'] = options['renderpass']
        if 'rendertype' in options:
            jb['rendertype'] = options['rendertype']
        if 'fileextension' in options:
            jb['fileextension'] = options['fileextension']
        if 'send_email' in options:
            jb['send_email'] = options['send_email']
        if 'email_recipients' in options:
            jb['email_recipients'] = options['email_recipients']
        # limits
        if 'os' in limits:
            jb['limits']['os'] = limits['os']
        if 'depend' in limits:
            jb['limits']['depend'] = limits['depend']
        if 'minram' in limits:
            jb['limits']['minram'] = limits['minram']
        if 'mincores' in limits:
            jb['limits']['mincores'] = limits['mincores']
        if 'pool' in limits:
            jb['limits']['pool'] = limits['pool']

        self.update(jb)
Ejemplo n.º 3
0
def main():
    # parse arguments
    parser = OptionParser()
    parser.usage = "%prog [options] -n name -r renderer -f scenefile"
    parser.add_option("-s", "--startframe",
                      dest="startframe", default=1, help="first frame")
    parser.add_option("-e", "--endframe",
                      dest="endframe", default=1, help="last frame")
    parser.add_option("-b", "--blocksize",
                      dest="blocksize", default=1, help="size of block")
    parser.add_option("-y", "--priority",
                      dest="priority", default=1, help="priority of each block")
    parser.add_option("-n", "--name",
                      dest="name", default=None, help="name of job")
    parser.add_option("-r", "--renderer",
                      dest="renderer", help="render type (maya|blender|mentalray)")
    parser.add_option("-f", "--scenefile",
                      dest="scenefile", default=None, help="path to scenefile")
    parser.add_option("-p", "--pool",
                      dest="pool", default=None, help="pool of computers")
    parser.add_option("-o", "--options",
                      dest="options", default="{}", help="specific options for renderer as Python dict")
    parser.add_option("--retries",
                      dest="retries", default=1, help="number of retries for every task")
    parser.add_option("--owner",
                      dest="owner", default=getpass.getuser(), help="Owner of job. Default is current username.")
    parser.add_option("--os",
                      dest="os", default=None, help="Operating system.")
    parser.add_option("--minram",
                      dest="minram", default=0, help="Minimal RAM in GB.")
    parser.add_option("--mincores",
                      dest="mincores", default=0, help="Minimal CPU cores.")
    parser.add_option("--send-email",
                      action="store_true", dest="send_email", default=False, help="Send notification email when job is finished.")
    parser.add_option("--email-recipients",
                      dest="email_recipients", default=None, help="Recipients for notification email.")
    parser.add_option("-w", "--wait",
                      action="store_true", dest="wait", default=False, help="wait for job to finish")
    parser.add_option("-v", "--verbose",
                      action="store_true", dest="verbose", default=False, help="verbose output")
    (options, args) = parser.parse_args()

    # set limits
    limits = dict()
    limits['pool_name'] = options.pool
    limits['os'] = options.os
    limits['minram'] = int(options.minram)
    limits['mincores'] = int(options.mincores)

    options_var = eval(options.options)
    options_var['send_email'] = options.send_email
    options_var['email_recipients'] = options.email_recipients

    # add default rendertype if missing
    if "rendertype" not in options_var:
        options_var['rendertype'] = "animation"

    # initialize DrQueue job
    job = DrQueueJob(options.name, int(options.startframe), int(options.endframe), int(options.blocksize),int(options.priority), options.renderer, options.scenefile, options.retries, options.owner, options_var, "send_job.py", limits)

    # save job in database
    job['job_status'] = 'ready'

    # check the condition of each job
    # check job name
    if job['name'] in DrQueueJob.query_jobnames():
        raise ValueError("Job name %s is already used!" % job['name'])

    # check frame numbers
    if not (job['startframe'] >= 0):
        raise ValueError("Invalid value for startframe. Has to be equal or greater than 1.")

    if not (job['endframe'] >= 0):
        raise ValueError("Invalid value for endframe. Has to be equal or greater than 1.")

    if not (job['endframe'] >= job['startframe']):
        raise ValueError("Invalid value for endframe. Has be to equal or greater than startframe.")

    if job['endframe'] > job['startframe']:
        if not (job['endframe'] - job['startframe'] >= job['blocksize']):
            raise ValueError("Invalid value for blocksize. Has to be equal or lower than endframe-startframe.")

    if job['endframe'] == job['startframe']:
        if job['blocksize'] != 1:
            raise ValueError("Invalid value for blocksize. Has to be equal 1 if endframe equals startframe.")

    if job['name'] == "":
        raise ValueError("No name of job given!")
    if DrQueue.check_renderer_support(job['renderer']) == False:
        raise ValueError("Render called \"%s\" not supported!" % job['renderer'])
    if job['scenefile'] == "":
        raise ValueError("No scenefile given!")
    # save job
    DrQueueJob.store_db(job)
Ejemplo n.º 4
0
    def __init__(self,
                 name,
                 startframe,
                 endframe,
                 blocksize,
                 renderer,
                 scenefile,
                 retries=1,
                 owner=getpass.getuser(),
                 options={},
                 created_with=None,
                 limits={}):
        dict.__init__(self)
        # mandatory elements
        jb = {
            'name': name,
            'startframe': int(startframe),
            'endframe': int(endframe),
            'blocksize': int(blocksize),
            'renderer': renderer,
            'scenefile': scenefile,
            'retries': int(retries),
            'owner': owner,
            'submit_time': datetime.datetime.now(),
            'requeue_time': False,
            'created_with': created_with,
            'enabled': True,
            'limits': {}
        }

        if name == "":
            raise ValueError("No name of job given!")
        if not (endframe > startframe):
            raise ValueError("Endframe must be bigger than startframe!")
        if blocksize < 1:
            raise ValueError("Blocksize needs to be at least 1!")
        if DrQueue.check_renderer_support(renderer) == False:
            raise ValueError("Render called \"%s\" not supported!" % renderer)
        if scenefile == "":
            raise ValueError("No scenefile given!")

        # optional elements
        if 'renderdir' in options:
            jb['renderdir'] = options['renderdir']
        if 'projectdir' in options:
            jb['projectdir'] = options['projectdir']
        if 'configdir' in options:
            jb['configdir'] = options['configdir']
        if 'imagefile' in options:
            jb['imagefile'] = options['imagefile']
        if 'precommand' in options:
            jb['precommand'] = options['precommand']
        if 'postcommand' in options:
            jb['postcommand'] = options['postcommand']
        if 'viewcommand' in options:
            jb['viewcommand'] = options['viewcommand']
        if 'worldfile' in options:
            jb['worldfile'] = options['worldfile']
        if 'terrainfile' in options:
            jb['terrainfile'] = options['terrainfile']
        if 'composition' in options:
            jb['composition'] = options['composition']
        if 'camera' in options:
            jb['camera'] = options['camera']
        if 'resx' in options:
            jb['resx'] = options['resx']
        if 'resy' in options:
            jb['resy'] = options['resy']
        if 'renderpass' in options:
            jb['renderpass'] = options['renderpass']
        if 'rendertype' in options:
            jb['rendertype'] = options['rendertype']
        if 'fileextension' in options:
            jb['fileextension'] = options['fileextension']
        if 'send_email' in options:
            jb['send_email'] = options['send_email']
        if 'email_recipients' in options:
            jb['email_recipients'] = options['email_recipients']
        if 'custom_command' in options:
            jb['custom_command'] = options['custom_command']
        # limits
        if 'os' in limits:
            jb['limits']['os'] = limits['os']
        if 'depend' in limits:
            jb['limits']['depend'] = limits['depend']
        if 'minram' in limits:
            jb['limits']['minram'] = limits['minram']
        if 'mincores' in limits:
            jb['limits']['mincores'] = limits['mincores']
        if 'pool_name' in limits:
            jb['limits']['pool_name'] = limits['pool_name']

        self.update(jb)
Ejemplo n.º 5
0
    def job_run(self, job):
        """Create and queue tasks from job object"""

        # check job name
        if job['name'] in DrQueueJob.query_jobnames():
            raise ValueError("Job name %s is already used!" % job['name'])
            return False

        # save job in database
        job_id = DrQueueJob.store_db(job)

        # job_id from db is be used as session name
        self.ip_client.session.session = str(job_id)

        # set owner of job
        self.ip_client.session.username = job['owner']

        # set number of retries for each task
        self.lbview.retries = job['retries']

        # depend on another job (it's tasks)
        if ('depend' in job['limits']) and (job['limits']['depend'] != None):
            depend_job = self.query_job_by_name(job['limits']['depend'])
            depend_tasks = self.query_task_list(depend_job['_id'])
            task_ids = []
            for task in depend_tasks:
                task_ids.append(task['msg_id'])
            self.lbview.after = task_ids

        # check frame numbers
        if not (job['startframe'] >= 1):
            raise ValueError(
                "Invalid value for startframe. Has to be equal or greater than 1."
            )
            return False
        if not (job['endframe'] >= 1):
            raise ValueError(
                "Invalid value for endframe. Has to be equal or greater than 1."
            )
            return False
        if not (job['endframe'] >= job['startframe']):
            raise ValueError(
                "Invalid value for endframe. Has be to equal or greater than startframe."
            )
            return False
        if job['endframe'] > job['startframe']:
            if not (job['endframe'] - job['startframe'] >= job['blocksize']):
                raise ValueError(
                    "Invalid value for blocksize. Has to be equal or lower than endframe-startframe."
                )
                return False
        if job['endframe'] == job['startframe']:
            if job['blocksize'] != 1:
                raise ValueError(
                    "Invalid value for blocksize. Has to be equal 1 if endframe equals startframe."
                )
                return False

        task_frames = list(
            range(job['startframe'], job['endframe'] + 1, job['blocksize']))
        ar = None
        for x in task_frames:

            # prepare script input
            env_dict = {
                'DRQUEUE_FRAME': x,
                'DRQUEUE_BLOCKSIZE': job['blocksize'],
                'DRQUEUE_ENDFRAME': job['endframe'],
                'DRQUEUE_SCENEFILE': job['scenefile']
            }

            # log filename
            if job['created_with'] == "DrQueueOnRails":
                # take job directory name
                env_dict['DRQUEUE_LOGFILE'] = job['scenefile'].split(
                    "/")[-2] + "-" + str(x) + "_" + str(x + job['blocksize'] -
                                                        1) + ".log"
            else:
                # take job name
                env_dict['DRQUEUE_LOGFILE'] = job['name'] + "-" + str(
                    x) + "_" + str(x + job['blocksize'] - 1) + ".log"

            # optional elements
            if 'renderdir' in job:
                env_dict['DRQUEUE_RENDERDIR'] = job['renderdir']
            if 'projectdir' in job:
                env_dict['DRQUEUE_PROJECTDIR'] = job['projectdir']
            if 'configdir' in job:
                env_dict['DRQUEUE_CONFIGDIR'] = job['configdir']
            if 'imagefile' in job:
                env_dict['DRQUEUE_IMAGEFILE'] = job['imagefile']
            if 'precommand' in job:
                env_dict['DRQUEUE_PRECOMMAND'] = job['precommand']
            if 'renderer' in job:
                env_dict['DRQUEUE_RENDERER'] = job['renderer']
            if 'fileformat' in job:
                env_dict['DRQUEUE_FILEFORMAT'] = job['fileformat']
            if 'postcommand' in job:
                env_dict['DRQUEUE_POSTCOMMAND'] = job['postcommand']
            if 'viewcommand' in job:
                env_dict['DRQUEUE_VIEWCOMMAND'] = job['viewcommand']
            if 'worldfile' in job:
                env_dict['DRQUEUE_WORLDFILE'] = job['worldfile']
            if 'terrainfile' in job:
                env_dict['DRQUEUE_TERRAINFILE'] = job['terrainfile']
            if 'composition' in job:
                env_dict['DRQUEUE_COMPOSITION'] = job['composition']
            if 'camera' in job:
                env_dict['DRQUEUE_CAMERA'] = job['camera']
            if 'resx' in job:
                env_dict['DRQUEUE_RESX'] = job['resx']
            if 'resy' in job:
                env_dict['DRQUEUE_RESY'] = job['resy']
            if 'renderpass' in job:
                env_dict['DRQUEUE_RENDERPASS'] = job['renderpass']
            if 'rendertype' in job:
                env_dict['DRQUEUE_RENDERTYPE'] = job['rendertype']
            if 'fileextension' in job:
                env_dict['DRQUEUE_FILEEXTENSION'] = job['fileextension']
            if 'stepframe' in job:
                env_dict['DRQUEUE_STEPFRAME'] = job['stepframe']
            if 'custom_bucket' in job:
                env_dict['DRQUEUE_CUSTOM_BUCKET'] = job['custom_bucket']
            if 'bucketsize' in job:
                env_dict['DRQUEUE_BUCKETSIZE'] = job['bucketsize']
            if 'custom_lod' in job:
                env_dict['DRQUEUE_CUSTOM_LOD'] = job['custom_lod']
            if 'lod' in job:
                env_dict['DRQUEUE_LOD'] = job['lod']
            if 'custom_varyaa' in job:
                env_dict['DRQUEUE_CUSTOM_VARYAA'] = job['custom_varyaa']
            if 'varyaa' in job:
                env_dict['DRQUEUE_VARYAA'] = job['varyaa']
            if 'raytrace' in job:
                env_dict['DRQUEUE_RAYTRACE'] = job['raytrace']
            if 'antialias' in job:
                env_dict['DRQUEUE_ANTIALIAS'] = job['antialias']
            if 'custom_bdepth' in job:
                env_dict['DRQUEUE_CUSTOM_BDEPTH'] = job['custom_bdepth']
            if 'bdepth' in job:
                env_dict['DRQUEUE_BDEPTH'] = job['bdepth']
            if 'custom_zdepth' in job:
                env_dict['DRQUEUE_CUSTOM_ZDEPTH'] = job['custom_zdepth']
            if 'zdepth' in job:
                env_dict['DRQUEUE_ZDEPTH'] = job['zdepth']
            if 'custom_cracks' in job:
                env_dict['DRQUEUE_CUSTOM_CRACKS'] = job['custom_cracks']
            if 'cracks' in job:
                env_dict['DRQUEUE_CRACKS'] = job['cracks']
            if 'custom_quality' in job:
                env_dict['DRQUEUE_CUSTOM_QUALITY'] = job['custom_quality']
            if 'quality' in job:
                env_dict['DRQUEUE_QUALITY'] = job['quality']
            if 'custom_qfiner' in job:
                env_dict['DRQUEUE_CUSTOM_QFINER'] = job['custom_qfiner']
            if 'qfiner' in job:
                env_dict['DRQUEUE_QFINER'] = job['qfiner']
            if 'custom_smultiplier' in job:
                env_dict['DRQUEUE_CUSTOM_SMULTIPLIER'] = job[
                    'custom_smultiplier']
            if 'smultiplier' in job:
                env_dict['DRQUEUE_SMULTIPLIER'] = job['smultiplier']
            if 'custom_mpcache' in job:
                env_dict['DRQUEUE_CUSTOM_MPCACHE'] = job['custom_mpcache']
            if 'mpcache' in job:
                env_dict['DRQUEUE_MPCACHE'] = job['mpcache']
            if 'custom_smpolygon' in job:
                env_dict['DRQUEUE_CUSTOM_SMPOLYGON'] = job['custom_smpolygon']
            if 'smpolygon' in job:
                env_dict['DRQUEUE_SMPOLYGON'] = job['smpolygon']
            if 'custom_wh' in job:
                env_dict['DRQUEUE_CUSTOM_WH'] = job['custom_wh']
            if 'custom_type' in job:
                env_dict['DRQUEUE_CUSTOM_TYPE'] = job['custom_type']
            if 'ctype' in job:
                env_dict['DRQUEUE_CTYPE'] = job['ctype']
            if 'skipframes' in job:
                env_dict['DRQUEUE_SKIPFRAMES'] = job['skipframes']
            if 'custom_command' in job:
                env_dict['DRQUEUE_CUSTOM_COMMAND'] = job['custom_command']

            # set dependencies
            dep_dict = {}
            dep_dict['job_id'] = job_id
            if ('os' in job['limits']) and (job['limits']['os'] != None):
                dep_dict['os_name'] = job['limits']['os']
            if ('minram' in job['limits']) and (job['limits']['minram'] > 0):
                dep_dict['minram'] = job['limits']['minram']
            if ('mincores'
                    in job['limits']) and (job['limits']['mincores'] > 0):
                dep_dict['mincores'] = job['limits']['mincores']
            if ('pool_name'
                    in job['limits']) and (job['limits']['pool_name'] != None):
                dep_dict['pool_name'] = job['limits']['pool_name']
            run_script_with_env_and_deps = dependent(
                DrQueue.run_script_with_env, DrQueue.check_deps, dep_dict)

            # run task on cluster
            render_script = DrQueue.get_rendertemplate(job['renderer'])
            ar = self.lbview.apply(run_script_with_env_and_deps, render_script,
                                   env_dict)
            # wait for pyzmq send to complete communication (avoid race condition)
            ar.wait_for_send()

        # append email task behind last task if requested
        if ('send_email' in job) and (job['send_email'] == True):
            self.lbview.after = ar
            # run email task
            mail_ar = self.lbview.apply(DrQueue.send_email, job['name'],
                                        job['email_recipients'])
            # wait for pyzmq send to complete communication (avoid race condition)
            mail_ar.wait_for_send()
        return True
Ejemplo n.º 6
0
    def job_run(self, job):
        """Create and queue tasks from job object"""

        # check job name
        if job["name"] in DrQueueJob.query_jobnames():
            raise ValueError("Job name %s is already used!" % job["name"])
            return False

        # run job only on matching os
        os_list = self.query_engines_of_os(job["limits"]["os"])

        # run job only on matching minram
        minram_list = self.query_engines_with_minram(job["limits"]["minram"])

        # run job only on matching mincores
        mincores_list = self.query_engines_with_mincores(job["limits"]["mincores"])

        # check pool members
        pool_list = self.query_engines_of_pool(job["limits"]["pool"])

        # check limits
        self.match_all_limits(os_list, minram_list, mincores_list, pool_list)

        # save job in database
        job_id = DrQueueJob.store_db(job)

        # job_id from db is be used as session name
        self.ip_client.session.session = str(job_id)

        # set owner of job
        self.ip_client.session.username = job["owner"]

        # set number of retries for each task
        self.lbview.retries = job["retries"]

        # depend on another job (it's tasks)
        if ("depend" in job["limits"]) and (job["limits"]["depend"] != None):
            depend_job = self.query_job_by_name(job["limits"]["depend"])
            depend_tasks = self.query_task_list(depend_job["_id"])
            task_ids = []
            for task in depend_tasks:
                task_ids.append(task["msg_id"])
            self.lbview.after = task_ids

        # check frame numbers
        if not (job["startframe"] >= 1):
            raise ValueError("Invalid value for startframe. Has to be equal or greater than 1.")
            return False
        if not (job["endframe"] >= 1):
            raise ValueError("Invalid value for endframe. Has to be equal or greater than 1.")
            return False
        if not (job["endframe"] >= job["startframe"]):
            raise ValueError("Invalid value for endframe. Has be to equal or greater than startframe.")
            return False
        if job["endframe"] > job["startframe"]:
            if not (job["endframe"] - job["startframe"] >= job["blocksize"]):
                raise ValueError("Invalid value for blocksize. Has to be equal or lower than endframe-startframe.")
                return False
        if job["endframe"] == job["startframe"]:
            if job["blocksize"] != 1:
                raise ValueError("Invalid value for blocksize. Has to be equal 1 if endframe equals startframe.")
                return False

        task_frames = range(job["startframe"], job["endframe"] + 1, job["blocksize"])
        for x in task_frames:
            # prepare script input
            env_dict = {
                "DRQUEUE_FRAME": x,
                "DRQUEUE_BLOCKSIZE": job["blocksize"],
                "DRQUEUE_ENDFRAME": job["endframe"],
                "DRQUEUE_SCENEFILE": job["scenefile"],
                "DRQUEUE_LOGFILE": job["name"] + "-" + str(x) + "_" + str(x + job["blocksize"] - 1) + ".log",
            }

            # optional elements
            if "renderdir" in job:
                env_dict["DRQUEUE_RENDERDIR"] = job["renderdir"]
            if "projectdir" in job:
                env_dict["DRQUEUE_PROJECTDIR"] = job["projectdir"]
            if "configdir" in job:
                env_dict["DRQUEUE_CONFIGDIR"] = job["configdir"]
            if "imagefile" in job:
                env_dict["DRQUEUE_IMAGEFILE"] = job["imagefile"]
            if "precommand" in job:
                env_dict["DRQUEUE_PRECOMMAND"] = job["precommand"]
            if "renderer" in job:
                env_dict["DRQUEUE_RENDERER"] = job["renderer"]
            if "fileformat" in job:
                env_dict["DRQUEUE_FILEFORMAT"] = job["fileformat"]
            if "postcommand" in job:
                env_dict["DRQUEUE_POSTCOMMAND"] = job["postcommand"]
            if "viewcommand" in job:
                env_dict["DRQUEUE_VIEWCOMMAND"] = job["viewcommand"]
            if "worldfile" in job:
                env_dict["DRQUEUE_WORLDFILE"] = job["worldfile"]
            if "terrainfile" in job:
                env_dict["DRQUEUE_TERRAINFILE"] = job["terrainfile"]
            if "composition" in job:
                env_dict["DRQUEUE_COMPOSITION"] = job["composition"]
            if "camera" in job:
                env_dict["DRQUEUE_CAMERA"] = job["camera"]
            if "resx" in job:
                env_dict["DRQUEUE_RESX"] = job["resx"]
            if "resy" in job:
                env_dict["DRQUEUE_RESY"] = job["resy"]
            if "renderpass" in job:
                env_dict["DRQUEUE_RENDERPASS"] = job["renderpass"]
            if "rendertype" in job:
                env_dict["DRQUEUE_RENDERTYPE"] = job["rendertype"]
            if "fileextension" in job:
                env_dict["DRQUEUE_FILEEXTENSION"] = job["fileextension"]
            if "stepframe" in job:
                env_dict["DRQUEUE_STEPFRAME"] = job["stepframe"]
            if "custom_bucket" in job:
                env_dict["DRQUEUE_CUSTOM_BUCKET"] = job["custom_bucket"]
            if "bucketsize" in job:
                env_dict["DRQUEUE_BUCKETSIZE"] = job["bucketsize"]
            if "custom_lod" in job:
                env_dict["DRQUEUE_CUSTOM_LOD"] = job["custom_lod"]
            if "lod" in job:
                env_dict["DRQUEUE_LOD"] = job["lod"]
            if "custom_varyaa" in job:
                env_dict["DRQUEUE_CUSTOM_VARYAA"] = job["custom_varyaa"]
            if "varyaa" in job:
                env_dict["DRQUEUE_VARYAA"] = job["varyaa"]
            if "raytrace" in job:
                env_dict["DRQUEUE_RAYTRACE"] = job["raytrace"]
            if "antialias" in job:
                env_dict["DRQUEUE_ANTIALIAS"] = job["antialias"]
            if "custom_bdepth" in job:
                env_dict["DRQUEUE_CUSTOM_BDEPTH"] = job["custom_bdepth"]
            if "bdepth" in job:
                env_dict["DRQUEUE_BDEPTH"] = job["bdepth"]
            if "custom_zdepth" in job:
                env_dict["DRQUEUE_CUSTOM_ZDEPTH"] = job["custom_zdepth"]
            if "zdepth" in job:
                env_dict["DRQUEUE_ZDEPTH"] = job["zdepth"]
            if "custom_cracks" in job:
                env_dict["DRQUEUE_CUSTOM_CRACKS"] = job["custom_cracks"]
            if "cracks" in job:
                env_dict["DRQUEUE_CRACKS"] = job["cracks"]
            if "custom_quality" in job:
                env_dict["DRQUEUE_CUSTOM_QUALITY"] = job["custom_quality"]
            if "quality" in job:
                env_dict["DRQUEUE_QUALITY"] = job["quality"]
            if "custom_qfiner" in job:
                env_dict["DRQUEUE_CUSTOM_QFINER"] = job["custom_qfiner"]
            if "qfiner" in job:
                env_dict["DRQUEUE_QFINER"] = job["qfiner"]
            if "custom_smultiplier" in job:
                env_dict["DRQUEUE_CUSTOM_SMULTIPLIER"] = job["custom_smultiplier"]
            if "smultiplier" in job:
                env_dict["DRQUEUE_SMULTIPLIER"] = job["smultiplier"]
            if "custom_mpcache" in job:
                env_dict["DRQUEUE_CUSTOM_MPCACHE"] = job["custom_mpcache"]
            if "mpcache" in job:
                env_dict["DRQUEUE_MPCACHE"] = job["mpcache"]
            if "custom_smpolygon" in job:
                env_dict["DRQUEUE_CUSTOM_SMPOLYGON"] = job["custom_smpolygon"]
            if "smpolygon" in job:
                env_dict["DRQUEUE_SMPOLYGON"] = job["smpolygon"]
            if "custom_wh" in job:
                env_dict["DRQUEUE_CUSTOM_WH"] = job["custom_wh"]
            if "custom_type" in job:
                env_dict["DRQUEUE_CUSTOM_TYPE"] = job["custom_type"]
            if "ctype" in job:
                env_dict["DRQUEUE_CTYPE"] = job["ctype"]
            if "skipframes" in job:
                env_dict["DRQUEUE_SKIPFRAMES"] = job["skipframes"]

            # run task on cluster
            render_script = DrQueue.get_rendertemplate(job["renderer"])
            ar = self.lbview.apply(DrQueue.run_script_with_env, render_script, env_dict)
            # wait for pyzmq send to complete communication (avoid race condition)
            ar.wait_for_send()
        return True