如何重新启动Google App Engine标准服务 [英] How to restart Google App Engine Standard Service

查看:66
本文介绍了如何重新启动Google App Engine标准服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:我有一个可提供交互式图形和数据分析的应用程序.为了计算曲线图和数据摘要,它使用在App初始化时通过查询google BigQuery加载的数据集.然后,数据将作为全局变量保存(在内存中),并用于可能由不同用户运行的所有数据计算和绘图(每个用户在其会话中保存自己的过滤器/掩码).

Context: I have an app that serves interactive graphs and data analysis. In order to calculate plots and data summaries, it uses a dataset that is loaded upon App initialization by querying google BigQuery. The data is then kept as a global variable (in memory) and is used in all data calculations and plots that might be run by different users (each user saves in their session their own filters/mask).

该数据集每天晚上在BigQuery中更改一次(我知道刷新的确切日期时间).在BigQuery中刷新数据后,我希望刷新数据集的全局变量.

This dataset changes in BigQuery once per day during the night (I know the exact datetime of refresh). Once the data is refreshed in BigQuery, I want the global variable of the dataset to be refreshed.

我知道正确的解决方案是针对每个用户请求调用数据库,但是BigQuery对请求的高延迟并不能使它成为一个好的解决方案,并且我不能使用其他数据库.

I know that the proper solution would be to call a Database on each user request, but BigQuery high delay on requests doesn't make this a good solution, and I can't use another DB.

到目前为止,我遇到的唯一解决方案是在刷新BigQuery数据后重新启动Google App Engine服务(所有实例).请注意,这应该是有计划的动作,以编程方式完成.

The only solution I've came across so far is to restart the Google App Engine service (all instances) after BigQuery data refresh. Please note that this should be a scheduled action, done programatically.

我的问题:

  • 如果重新启动服务是最好的解决方案,我应该如何重新启动服务?
  • 如果还有另一种方法可以完成我想要的事情,请告诉我

推荐答案

我终于找到了一种方法,可以使用Python API发现客户端和服务帐户以编程方式重新启动所有实例.它首先获取活动实例的列表,并删除所有实例.然后,执行一个简单的请求以启动其中一个.

I finally found a way to restart all instances programatically, by using the Python API discovery Client and a service account. It first gets the list of active instances and delets all of them. Then, performs a simple request to initiate one of them.

import requests
from apiclient.discovery import build
from google.oauth2 import service_account

credentials = service_account.Credentials.from_service_account_file('credentials.json')
scoped_credentials = credentials.with_scopes(['https://www.googleapis.com/auth/appengine.admin',"https://www.googleapis.com/auth/cloud-platform"])
appengine = build(serviceName="appengine",version="v1",credentials=scoped_credentials)

VERSION_ID = "version_id"
PROJECT_ID = "project_id"
SERVICE_ID = "appengine_service_name"
APP_URL = "http://some_url.com"

active_instances_dict = appengine.apps().services().versions().instances().list(servicesId=SERVICE_ID,appsId=PROJECT_ID,versionsId=VERSION_ID).execute()
list_of_instances = active_instances_dict["instances"]

for instance in list_of_instances:
    appengine.apps().services().versions().instances().delete(servicesId=SERVICE_ID,appsId=PROJECT_ID,
                  versionsId=VERSION_ID,instancesId=instance["id"]).execute()

requests.get(url=APP_URL)

这篇关于如何重新启动Google App Engine标准服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆