def spawn_update_server(): client = docker.from_env() run_orchest_ctl(client, ["updateserver"]) return ""
def background_task(): client = docker.from_env() try: log_update("Starting update ...\n") # get latest orchest-ctl log_update("Pulling orchest-ctl ...\n") try: client.images.pull("orchest/orchest-ctl:latest") except docker.errors.APIError as e: logging.error(e) log_update("Pulled orchest-ctl. Starting update ...\n") try: container = run_orchest_ctl(client, ["update", "--mode=web"]) for line in container.logs(stream=True): log_update(line.decode()) except Exception as e: log_update("Error run_orchest_ctl: %s" % e) log_update("Update complete! Restarting Orchest " "... (this can take up to 15 seconds)\n") except Exception as e: log_update("Error during updating: %s" % e) with open(UPDATE_COMPLETE_FILE, "w") as f: f.write("true") # wait at most 10 seconds for file to be read for _ in range(10): if os.path.exists(UPDATE_COMPLETE_FILE): time.sleep(1) else: break try: # Restart Orchest given the flags. ctl_command = ["restart"] # Note that it won't work as --port {port}. ctl_command.append(f"--port={CONFIG_CLASS.PORT}") if CONFIG_CLASS.FLASK_ENV == "development": ctl_command.append("--dev") if CONFIG_CLASS.CLOUD: ctl_command.append("--cloud") # Note: this depends on the detached Docker orchest_ctl # finishing without waiting for the response as the # update-server is shutdown as part of the restart command. run_orchest_ctl(client, ctl_command) except docker.errors.APIError as e: print(e)
def background_task(json_obj): client = docker.from_env() try: log_update("Starting update ...\n") # get latest orchest-ctl log_update("Pulling orchest-ctl ...\n") try: client.images.pull("orchest/orchest-ctl:latest") except docker.errors.APIError as e: logging.error(e) log_update("Pulled orchest-ctl. Starting update ...\n") try: container = run_orchest_ctl(client, ["update", "--mode=web"]) for line in container.logs(stream=True): log_update(line.decode()) except Exception as e: log_update("Error run_orchest_ctl: %s" % e) log_update("Update complete! Restarting Orchest " "... (this can take up to 15 seconds)\n") except Exception as e: log_update("Error during updating: %s" % e) with open(UPDATE_COMPLETE_FILE, "w") as f: f.write("true") # wait at most 10 seconds for file to be read for _ in range(10): if os.path.exists(UPDATE_COMPLETE_FILE): time.sleep(1) else: break try: # Restart Orchest in either regular or dev mode. ctl_command = ["restart"] # Note: this depends on the detached # Docker orchest_ctl finishing # without waiting for the response # as the update-server is shutdown as part # of the restart command. dev_mode = json_obj.get("mode") == "dev" if dev_mode: ctl_command += ["--mode=dev"] run_orchest_ctl(client, ctl_command) except docker.errors.APIError as e: print(e)
def restart_server(): client = docker.from_env() if request.args.get("mode") == "dev": run_orchest_ctl(client, ["restart", "--mode=dev"]) else: run_orchest_ctl(client, ["restart"]) return ""
def streaming_update(json_obj): try: dev_mode = json_obj.get("mode") == "dev" client = docker.from_env() yield "Starting update ...\n" # get latest orchest-ctl yield "Pulling orchest-ctl ...\n" try: client.images.pull("orchest/orchest-ctl:latest") except docker.errors.APIError as e: logging.error(e) yield "Pulled orchest-ctl. Starting update ...\n" gpu_flag = f"--{json_obj.get('gpu')}" language_flag = f"--lang={json_obj.get('language')}" try: container = run_orchest_ctl( client, ["update", "--mode=web", gpu_flag, language_flag]) for line in container.logs(stream=True): yield line.decode() except Exception as e: yield "Error run_orchest_ctl: %s" % e yield "Update complete! Restarting Orchest ... (this can take up to 15 seconds)\n" executor.submit(background_task, dev_mode) except Exception as e: yield "Error during updating: %s" % e
def restart_server(): client = docker.from_env() cmd = ["restart"] # Note that it won't work as --port {port}. cmd.append(f"--port={StaticConfig.PORT}") if StaticConfig.FLASK_ENV == "development": cmd.append("--dev") if StaticConfig.CLOUD: cmd.append("--cloud") run_orchest_ctl(client, cmd) return ""
def background_task(dev_mode): client = docker.from_env() # kill self try: container = client.containers.get("nginx-proxy") container.kill() container.remove() # restart Orchest in either dev mode start_command = ["start"] if dev_mode: start_command += ["dev"] run_orchest_ctl(client, start_command) container = client.containers.get("update-server") container.kill() except docker.errors.APIError as e: print(e)
def streaming_update(dev_mode): client = docker.from_env() yield "Starting update ...\n" # get latest orchest-ctl yield "Pulling orchest-ctl ...\n" try: client.images.pull("orchest/orchest-ctl:latest") except docker.errors.APIError as e: logging.error(e) yield "Pulled orchest-ctl. Starting update ...\n" container = run_orchest_ctl(client, ["update", "--mode=web"]) for line in container.logs(stream=True): yield line.decode() yield "Update complete! Restarting Orchest ... (this can take up to 15 seconds)\n" executor.submit(background_task, dev_mode)