2016-09-14 39 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

這可能不是你要找的東西,但它是一個可能實現你想要的方式。

在容器引擎上設置一個系統或類似的東西,它會自動從您的回購中提取最新的代碼,自動調整實例類型並自動執行重新部署。你可以讓它在不同的時間部署不同的實例類型。實例類的每一個變化都需要重新部署,但這些可能在理論上是完全自動的,所以這是可能的。

想法?這是你的可能解決方案嗎?

相關問題