@@ -219,18 +219,40 @@ def _get_application_status(self, app_id: str):
219219 )
220220 return response ["Result" ]["Status" ], response
221221
222- def _list_application (self ):
223- response = ve_request (
224- request_body = {},
225- action = "ListApplications" ,
226- ak = self .ak ,
227- sk = self .sk ,
228- service = "vefaas" ,
229- version = "2021-03-03" ,
230- region = "cn-beijing" ,
231- host = "open.volcengineapi.com" ,
232- )
233- return response ["Result" ]["Items" ]
222+ def _list_application (self , app_name : str = None ):
223+ page_size = 50
224+ page_number = 1
225+ all_items = []
226+ total_page = None
227+ while True :
228+ request_body = {
229+ "PageNumber" : page_number ,
230+ "PageSize" : page_size ,
231+ "Filters" : [{"Item" : {"Key" : "Name" , "Value" : [app_name ]}}],
232+ "OrderBy" : {"Key" : "CreateTime" , "Ascend" : False },
233+ }
234+ response = ve_request (
235+ request_body = request_body ,
236+ action = "ListApplications" ,
237+ ak = self .ak ,
238+ sk = self .sk ,
239+ service = "vefaas" ,
240+ version = "2021-03-03" ,
241+ region = "cn-beijing" ,
242+ host = "open.volcengineapi.com" ,
243+ )
244+ result = response .get ("Result" , {})
245+ items = result .get ("Items" , [])
246+ all_items .extend (items )
247+
248+ if total_page is None :
249+ total = result .get ("Total" , 0 )
250+ total_page = (total + page_size - 1 ) // page_size
251+
252+ if page_number >= total_page or not items :
253+ break
254+ page_number += 1
255+ return all_items
234256
235257 def _update_function_code (
236258 self ,
@@ -306,7 +328,7 @@ def _update_function_code(
306328 def get_application_details (self , app_id : str = None , app_name : str = None ):
307329 if not app_id and not app_name :
308330 raise ValueError ("app_id and app_name cannot be both empty." )
309- apps = self ._list_application ()
331+ apps = self ._list_application (app_name = app_name )
310332 if app_id :
311333 for app in apps :
312334 if app ["Id" ] == app_id :
@@ -318,7 +340,7 @@ def get_application_details(self, app_id: str = None, app_name: str = None):
318340 return app
319341
320342 def find_app_id_by_name (self , name : str ):
321- apps = self ._list_application ()
343+ apps = self ._list_application (app_name = name )
322344 for app in apps :
323345 if app ["Name" ] == name :
324346 return app ["Id" ]
0 commit comments