Skip to content

Commit

Permalink
fix: no empty calls paged tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Sciator committed Nov 22, 2023
1 parent f72b3cc commit 082231c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions influxdb_client/client/tasks_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def __iter__(self):

def __next__(self):
if not self.values:
self.values, self.next = self.next()
if self.next:
self.values, self.next = self.next()
if not self.values:
raise StopIteration
return self.values.pop(0)
Expand Down Expand Up @@ -61,18 +62,18 @@ def _find_tasks_paged(self, **kwargs):
:key str org: filter tasks to a specific organization name
:key str org_id: filter tasks to a specific organization ID
:key int limit: the number of tasks to return in one page
:return: Tasks, Next
:return: Tasks, Next or None
"""
tasks = self._service.get_tasks(**kwargs).tasks
tasks_response = self._service.get_tasks(**kwargs)
tasks = tasks_response.tasks

has_next = tasks_response.links.next is not None
last_id = tasks[-1].id if tasks else None
def next():
if last_id is not None:
if has_next and last_id is not None:
return self._find_tasks_paged(**{**kwargs, 'after': last_id})
else:
def func():
raise Exception("There are no additional pages remaining for tasks.")
return [], func
return [], None

return tasks, next

Expand Down

0 comments on commit 082231c

Please sign in to comment.