def start_watcher(self, *args): """Start the background job watcher. Command for watch_button.""" utils.JobWatcher( self.base.selected_job_id(), self.data_path, self.selected_dir)
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)