@@ -102,30 +102,31 @@ def list_pipelines(session: Session) -> List[Any]:
102102 return matched_pipelines
103103
104104
105- def get_running_pipeline_count (session : Session , names : List [str ]) -> int :
105+ def get_running_pipeline_count (session : Session , pipeline_names : List [str ]) -> int :
106106 pipeline_counter = 0
107107 client = session .client ("codepipeline" )
108108
109- for p in names :
110- logger .info ("Getting pipeline executions for " + p )
111-
112- response = client .list_pipeline_executions (pipelineName = p )
113- pipeline_execution_summaries = response ["pipelineExecutionSummaries" ]
114-
115- while "nextToken" in response :
116- response = client .list_pipeline_executions (
117- pipelineName = p , nextToken = response ["nextToken" ]
118- )
119- pipeline_execution_summaries .extend (response ["pipelineExecutionSummaries" ])
120-
121- latest_execution = sorted (
122- pipeline_execution_summaries , key = lambda i : i ["startTime" ], reverse = True # type: ignore
123- )[0 ]
124- logger .info ("Latest Execution: " )
125- logger .info (latest_execution )
126-
127- if latest_execution ["status" ] == "InProgress" :
128- pipeline_counter += 1
109+ for name in pipeline_names :
110+ logger .info ("Getting pipeline executions for " + name )
111+ pipeline_execution_summaries = []
112+
113+ paginator = client .get_paginator ("list_pipeline_executions" )
114+ pages = paginator .paginate (pipelineName = name )
115+ for page in pages :
116+ pipeline_execution_summaries .extend (page ["pipelineExecutionSummaries" ])
117+
118+ if not pipeline_execution_summaries :
119+ # No executions for this pipeline in the last 12 months
120+ continue
121+ else :
122+ latest_execution = sorted (
123+ pipeline_execution_summaries , key = lambda i : i ["startTime" ], reverse = True # type: ignore
124+ )[0 ]
125+ logger .info ("Latest Execution: " )
126+ logger .info (latest_execution )
127+
128+ if latest_execution ["status" ] == "InProgress" :
129+ pipeline_counter += 1
129130
130131 logger .info ("The number of running pipelines is " + str (pipeline_counter ))
131132
0 commit comments