2016-09-14 64 views
1

我正在为Google App Engine项目使用后端实例。 (前端实例无法处理超过60秒的请求 - 我需要更长的时间。)在Google App Engine上以编程方式更改后端实例类

我选择了B4实例类型,因为有时负载很高。然而,在某些时候(比如凌晨2点到上午7点),负载很低,以至于有一个B4实例是过量的。

我想创建一个cron作业,在某些时间将该实例的类型更改为B2,并在其他时间返回到B4以节省成本。

但是,看着Modules API,我找不到办法。

那么我该怎么做呢?

通过Ramiel

得到一个答案,最后我用管理员API如下之后编辑:

# Construct the api client 
cred = GoogleCredentials.get_application_default() 
svc = discovery.build('appengine', 'v1', credentials=cred) 
vapi = svc.apps().services().versions() 

# get list of versions 
o = vapi.list(appsId=app_identity.get_application_id(), servicesId=modules.get_current_module_name()).execute() 

# PATCH all SERVING versions with the new instanceClass 
for v in o['versions']: 
    if v['servingStatus'] == 'SERVING': 
     result = vapi.patch(
      appsId=app_identity.get_application_id(), 
      servicesId=modules.get_current_module_name(), 
      versionsId=v['id'], 
      updateMask='instanceClass', 
      body={ 
       'instanceClass': instanceClass 
      } 
     ).execute() 

回答

0

这可能不是你要找的东西,但它是一个可能实现你想要的方式。

在容器引擎上设置一个系统或类似的东西,它会自动从您的回购中提取最新的代码,自动调整实例类型并自动执行重新部署。你可以让它在不同的时间部署不同的实例类型。实例类的每一个变化都需要重新部署,但这些可能在理论上是完全自动的,所以这是可能的。

想法?这是你的可能解决方案吗?

相关问题