Skip to content

Commit b461527

Browse files
author
Yuan
authored
Merge pull request #16 from scaleapi/add-next-token
Add next_token field in tasks query
2 parents b92d7fa + c2374a4 commit b461527

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

scaleapi/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ class ScaleInvalidRequest(ScaleException, ValueError):
3333

3434

3535
class Tasklist(list):
36-
def __init__(self, docs, total, limit, offset, has_more):
36+
def __init__(self, docs, total, limit, offset, has_more, next_token=None):
3737
super(Tasklist, self).__init__(docs)
3838
self.docs = docs
3939
self.total = total
4040
self.limit = limit
4141
self.offset = offset
4242
self.has_more = has_more
43-
43+
self.next_token = next_token
4444

4545
class ScaleClient(object):
4646
def __init__(self, api_key):
@@ -110,24 +110,28 @@ def cancel_task(self, task_id):
110110

111111
def tasks(self, **kwargs):
112112
"""Returns a list of your tasks.
113-
Returns up to 100 at a time, to get more use the offset param.
113+
Returns up to 100 at a time, to get more, use the next_token param passed back.
114+
115+
Note that offset is deprecated.
114116
115117
start/end_time are ISO8601 dates, the time range of tasks to fetch.
116118
status can be 'completed', 'pending', or 'canceled'.
117119
type is the task type.
118120
limit is the max number of results to display per page,
119-
offset is the number of results to skip (for showing more pages).
121+
next_token can be use to fetch the next page of tasks.
122+
offset (deprecated) is the number of results to skip (for showing more pages).
120123
"""
121124
allowed_kwargs = {'start_time', 'end_time', 'status', 'type', 'project',
122-
'batch', 'limit', 'offset', 'completed_before', 'completed_after'}
125+
'batch', 'limit', 'offset', 'completed_before', 'completed_after',
126+
'next_token'}
123127
for key in kwargs:
124128
if key not in allowed_kwargs:
125129
raise ScaleInvalidRequest('Illegal parameter %s for ScaleClient.tasks()'
126130
% key, None)
127131
response = self._getrequest('tasks', params=kwargs)
128132
docs = [Task(json, self) for json in response['docs']]
129133
return Tasklist(docs, response['total'], response['limit'],
130-
response['offset'], response['has_more'])
134+
response['offset'], response['has_more'], response.get('next_token'))
131135
def create_task(self, task_type, **kwargs):
132136
endpoint = 'task/' + task_type
133137
taskdata = self._postrequest(endpoint, payload=kwargs)

0 commit comments

Comments
 (0)