@@ -160,35 +160,44 @@ def find_run_by_id(self, id: str) -> Optional[WorkflowSearchResult]:
160160 return results [0 ] if (results := response .hits and response .hits .hits ) else None
161161
162162 @validate_arguments
163- def find_by_status_and_interval (
164- self , status : List [AtlanWorkflowPhase ], interval : int
163+ def find_runs_by_status_and_time_range (
164+ self ,
165+ status : List [AtlanWorkflowPhase ],
166+ started_at : Optional [str ] = None ,
167+ finished_at : Optional [str ] = None ,
165168 ) -> List [WorkflowSearchResult ]:
166169 """
167- Find workflows based on their status and interval
170+ Find workflows by status and optional time filters on startedAt and/or finishedAt.
168171
169- :param status: list of the status of the workflows to filter with
170- :param interval: time interval in hours to search for workflows
171- :returns: the list of workflows of the provided type, with the most-recently created first
172- :raises ValidationError: If the provided status is an invalid AtlanWorkflowPhase
172+ :param status: list of the workflow statuses to filter
173+ :param started_at: (optional) lower bound on 'status.startedAt' (e.g 'now-2h')
174+ :param finished_at: (optional) lower bound on 'status.finishedAt' (e.g 'now-1h')
175+ :returns: list of workflows matching the filters
176+ :raises ValidationError: if inputs are invalid
173177 :raises AtlanError: on any API communication issue
174178 """
179+ time_filters = []
180+
181+ if started_at :
182+ time_filters .append (Range (field = "status.startedAt" , gte = started_at ))
183+ if finished_at :
184+ time_filters .append (Range (field = "status.finishedAt" , gte = finished_at ))
175185
176186 run_lookup_query = Bool (
177187 must = [
178188 NestedQuery (
179189 query = Terms (
180190 field = "metadata.labels.workflows.argoproj.io/phase.keyword" ,
181- values = [state .value for state in status ],
191+ values = [s .value for s in status ],
182192 ),
183193 path = "metadata" ,
184194 ),
185- Range ( field = "status.finishedAt" , gt = f"now- { interval } h" ) ,
195+ * time_filters ,
186196 NestedQuery (
187197 query = Exists (field = "metadata.labels.workflows.argoproj.io/creator" ),
188198 path = "metadata" ,
189199 ),
190200 ],
191- must_not = [NestedQuery (query = Exists (field = "spec.shutdown" ), path = "spec" )],
192201 )
193202
194203 run_lookup_results = self ._find_runs (run_lookup_query )
0 commit comments