我正在爲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()
這正是我所需要的!謝謝! – yuku