def update(self, msg, progress=None): resp = utils.reply(self._req) resp["transitioning"] = "yes" resp["transitionMessage"] = msg resp["transitionProgress"] = progress publish(resp)
def _reply(self, req, response_data): if req is None: return None resp = utils.reply(req) resp.data = response_data return resp
def execute(self, event): if not _should_handle(self, event): return if len(event.data.items) == 0: return utils.reply(event) env = dict(os.environ) env["DSTACK_ACCESS_KEY"] = Config.access_key() env["DSTACK_SECRET_KEY"] = Config.secret_key() args = [Config.config_sh(), "--url", Config.config_url(event.data.configUrl)] for item in event.data.items: args.append(item) subprocess.check_call(*args, env=env) return utils.reply(event)
def execute(self, event): if not _should_handle(self, event): return resp = utils.reply(event) if Config.do_ping(): for type in types(): if hasattr(type, 'on_ping'): type.on_ping(event, resp) return resp
def _worker(queue, ppid): agent = Agent() marshaller = type_manager.get_type(type_manager.MARSHALLER) publisher = type_manager.get_type(type_manager.PUBLISHER) while True: try: req = None line = queue.get(True, 5) log.info("Request: %s" % line) req = marshaller.from_string(line) id = req.id start = time.time() try: log.info("Starting request %s for %s", id, req.name) resp = agent.execute(req) if resp is not None: publisher.publish(resp) finally: duration = time.time() - start log.info("Done request %s for %s [%s] seconds", id, req.name, duration) except Empty: if not _pid_exists(ppid): break except FailedToLock as e: log.info("%s for %s", e, req.name) except Exception as e: error_id = str(uuid.uuid4()) log.exception("%s : Unknown error", error_id) if not _pid_exists(ppid): break if req is not None: msg = "{0} : {1}".format(error_id, e) resp = utils.reply(req) if resp is not None: resp["transitioning"] = "error" resp["transitioningInternalMessage"] = msg publisher.publish(resp)