def run(self, env): try: self.task.started(TYPE) for extension in self.task.extensions: extension.started(TYPE) with hooks.task_run([self.task] + self.task.extensions): self._run(env) for extension in self.task.extensions: extension.finished(TYPE) self.task.finished(TYPE) except (ConnectionError, AMQPConnectionError): log.exception() for extension in self.task.extensions: extension.failed(TYPE) self.task.failed(TYPE) raise_error("Lost connection to AMQP server") except Exception as e: log.exception() for extension in self.task.extensions: extension.failed(TYPE) self.task.failed(TYPE) raise e finally: if self.connection is not None: utils.call_and_catch(self.connection.close) return self.task
def run(self, env): if self.is_aborted(): return try: self.task.started() with hooks.task_run(self.task): self.task.run(env.cache, force_build=self.force_build, force_upload=self.force_upload) except Exception as e: log.exception() self.task.failed() raise e else: self.task.finished() return self.task
def run(self, cache, force_upload=False, force_build=False): with self.tools: tasks = [self] + self.extensions available_locally = available_remotely = False for child in self.children: if not child.has_artifact(): continue if not cache.is_available_locally(child): raise_task_error_if(not cache.download(child), child, "failed to download task artifact") if not force_build: available_locally = all(map(cache.is_available_locally, tasks)) if available_locally and not force_upload: return available_remotely = cache.download_enabled() and \ all(map(cache.is_available_remotely, tasks)) if not available_locally and available_remotely: available_locally = cache.download(self) if force_build or not available_locally: with log.threadsink() as buildlog: if self.task.is_runnable(): log.verbose("Host: {0}", getenv("HOSTNAME", "localhost")) with cache.get_locked_artifact( self, discard=force_build) as artifact: if not cache.is_available_locally( self) or self.has_extensions(): with cache.get_context(self) as context: self.running() with self.tools.cwd(self.task.joltdir): hooks.task_prerun(self, context, self.tools) if self.is_goal() and self.options.debug: log.info("Entering debug shell") self.task.shell(context, self.tools) self.task.run(context, self.tools) hooks.task_postrun(self, context, self.tools) if not cache.is_available_locally(self): with self.tools.cwd(self.task.joltdir): hooks.task_prepublish( self, artifact, self.tools) self.task.publish(artifact, self.tools) self.task._verify_influence( context, artifact, self.tools) hooks.task_postpublish( self, artifact, self.tools) with open( fs.path.join( artifact.path, ".build.log"), "w") as f: f.write(buildlog.getvalue()) cache.commit(artifact) else: self.info( "Publication skipped, already in local cache" ) else: self.info( "Execution skipped, already in local cache") # Must upload the artifact while still holding its lock, otherwise the # artifact may become unpack():ed before we have a chance to. if force_upload or force_build or not available_remotely: raise_task_error_if( not cache.upload( self, force=force_upload, locked=False) and cache.upload_enabled(), self, "failed to upload task artifact") elif force_upload or not available_remotely: raise_task_error_if( not cache.upload(self, force=force_upload) and cache.upload_enabled(), self, "failed to upload task artifact") for extension in self.extensions: try: extension.started() with hooks.task_run(extension): extension.run(cache, force_upload, force_build) except Exception as e: extension.failed() raise e else: extension.finished()