pool_ref = client.pool.get(POOL_ID) os_flavor = os_flavor(pool_ref.virtual_machine_configuration.image_reference) pool_info = {'poolId': POOL_ID} # Create a pool model with an application template reference job_id = 'maya_test_{}_{}'.format(os_flavor.lower(), uuid.uuid4()) batch_parameters = {'id': job_id} batch_parameters['displayName'] = "Maya Integration Test using {}".format(os_flavor) batch_parameters['metadata'] = [{"name": "JobType", "value": "Maya"}] template_file = os.path.join(TEMPLATE_DIR, 'mayaSoftware-2017-{}.json'.format(os_flavor.lower())) batch_parameters['applicationTemplateInfo'] = {'filePath': template_file} application_params = {} batch_parameters['applicationTemplateInfo']['parameters'] = application_params application_params['outputs'] = job_id application_params['sceneFile'] = utils.format_scene_path(scene_file, utils.OperatingSystem[os_flavor.lower()]) application_params['projectData'] = maya_data application_params['assetScript'] = client.file.generate_sas_url(maya_data, 'asset_map.mel'.format(os_flavor.lower())) application_params['thumbScript'] = client.file.generate_sas_url(maya_data, 'generate_thumbnails.py') application_params['workspace'] = client.file.generate_sas_url(maya_data, 'workspace.mel') application_params['storageURL'] = generate_sas_token(storage_client, maya_data) application_params['frameStart'] = 1 application_params['frameEnd'] = 3 application_params['frameStep'] = 1 application_params['renderer'] = 'sw' batch_parameters['poolInfo'] = pool_info new_job = client.job.jobparameter_from_json(batch_parameters) client.job.add(new_job) # When job is finished, delete it along with input/output file groups
def submit(self, watch_job=False, download_dir=None): """Submit a new job. :param watch_job: Whether to launch the job watcher process once the job has submitted. :param download_dir: If launching the job watcher, a download directory must be specified. """ progress = None try: pool_os = self._get_os_flavor() job_id = "maya-render-{}".format(uuid.uuid4()) self.renderer.disable(False) progress = utils.ProgressBar(self._log) maya.refresh() mayaVersion = maya.about(version=True) if mayaVersion != "2017" and mayaVersion != "2018": raise Exception( "Unrecognized mayaVersion \"{}\", 2017 and 2018 are supported" .format(mayaVersion)) batch_parameters = {'id': job_id} batch_parameters['displayName'] = self.renderer.get_title() batch_parameters['metadata'] = [{ "name": "JobType", "value": "Maya" }] template_file = os.path.join( os.environ['AZUREBATCH_TEMPLATES'], "{}-{}-{}.json".format(self.renderer.render_engine, mayaVersion, pool_os.value.lower())) batch_parameters['applicationTemplateInfo'] = { 'filePath': template_file } application_params = {} batch_parameters['applicationTemplateInfo'][ 'parameters'] = application_params self._check_outputs() plugins = self._check_plugins() application_params['outputs'] = job_id self.ui.submit_status("Checking assets...") scene_file, renderer_data = self.renderer.get_jobdata() application_params['sceneFile'] = utils.format_scene_path( scene_file, pool_os) job_assets, progress = self.asset_manager.upload( renderer_data, progress, job_id, plugins, pool_os) application_params['projectData'] = job_assets['project'] application_params['assetScript'] = job_assets['path_map'] application_params['thumbScript'] = job_assets['thumb_script'] application_params['workspace'] = job_assets['workspace'] application_params[ 'storageURL'] = self.asset_manager.generate_sas_token( job_assets['project']) self._switch_tab() self.ui.submit_status("Configuring job...") progress.status("Configuring job...") job_params = self.renderer.get_params() application_params.update(job_params) self.ui.submit_status("Setting pool...") progress.status("Setting pool...") pool = self._configure_pool(self.renderer.get_title()) batch_parameters['poolInfo'] = pool batch_parameters[ 'commonEnvironmentSettings'] = self.env_manager.get_environment_settings( ) self.ui.submit_status("Final renderer configuration...") self.renderer.final_setup(batch_parameters, job_assets) self._log.debug(json.dumps(batch_parameters)) new_job = self.batch.job.jobparameter_from_json(batch_parameters) progress.is_cancelled() self.ui.submit_status("Submitting...") progress.status("Submitting...") self._log.debug("Submitting using {} threads.".format( self.batch.threads)) self._call(self.batch.job.add, new_job) maya.info("Job submitted successfully") if watch_job: utils.JobWatcher(new_job.id, self.data_path, download_dir) except CancellationException: maya.info("Job submission cancelled") except Exception as exp: self._log.error(str(exp)) exc_type, exc_value, exc_traceback = sys.exc_info() self._log.debug(''.join( traceback.format_exception(exc_type, exc_value, exc_traceback))) maya.error(str(exp)) finally: if progress: progress.end() self._switch_tab() self.renderer.disable(True)