Skip to content

Commit 2e5b027

Browse files
author
Astha Patni
authored
[CAT-126] ADD: pagination to ListSubmissions (#124)
1 parent 8184199 commit 2e5b027

File tree

4 files changed

+80
-44
lines changed

4 files changed

+80
-44
lines changed

examples/submission.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,13 @@
105105
job = client.call(SubmitReview(submission.id, changes=changes, rejected=rejected))
106106
job = client.call(JobStatus(job.id))
107107
print("Review", job.id, "has result", job.result)
108+
109+
"""
110+
Example 5
111+
Use the client paginator to retrieve all PROCESSING submissions
112+
Without the paginator, the hard limit is 1000
113+
"""
114+
sub_filter = SubmissionFilter(status="PROCESSING")
115+
for submission in client.paginate(ListSubmissions(filters=sub_filter)):
116+
print(f"Submission {submission.id}")
117+
# do other cool things

indico/queries/document_report.py

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,49 @@ class _DocumentReportList(BaseType):
1111
submissions: List[DocumentReport]
1212
pass
1313

14+
1415
class GetDocumentReport(PagedRequest):
15-
"""
16-
Query to generate a Document Report.
17-
Generates a paged request and paged response.
18-
See examples for a sample query.
19-
"""
20-
query = """
21-
query SubmissionsLog($filters: SubmissionLogFilter, $limit: Int){
22-
submissionsLog(filters: $filters, limit: $limit){
23-
submissions{
24-
datasetId
25-
workflowId
26-
status
27-
createdAt
28-
updatedAt
29-
updatedBy
30-
completedAt
31-
errors
32-
retrieved
33-
inputFiles{
34-
filename
35-
submissionId
36-
}
37-
}
38-
pageInfo{
39-
startCursor
40-
endCursor
41-
hasNextPage
42-
aggregateCount
43-
}
44-
}
45-
}
46-
"""
16+
"""
17+
Query to generate a Document Report.
18+
Generates a paged request and paged response.
19+
See examples for a sample query.
20+
"""
4721

48-
def __init__(self, filters: Union[dict, DocumentReportFilter] = None, limit: int = None):
49-
variables = {
50-
"filters": filters,
51-
"limit": limit
22+
query = """
23+
query SubmissionsLog($filters: SubmissionLogFilter, $limit: Int, $after: Int){
24+
submissionsLog(filters: $filters, limit: $limit, after: $after){
25+
submissions{
26+
datasetId
27+
workflowId
28+
status
29+
createdAt
30+
updatedAt
31+
updatedBy
32+
completedAt
33+
errors
34+
retrieved
35+
inputFiles{
36+
filename
37+
submissionId
38+
}
39+
}
40+
pageInfo{
41+
startCursor
42+
endCursor
43+
hasNextPage
44+
aggregateCount
45+
}
46+
}
5247
}
48+
"""
49+
50+
def __init__(
51+
self, filters: Union[dict, DocumentReportFilter] = None, limit: int = None
52+
):
53+
variables = {"filters": filters, "limit": limit}
5354
super().__init__(self.query, variables=variables)
5455

55-
def process_response(self, response):
56-
return _DocumentReportList(**super().process_response(response)["submissionsLog"]).submissions
56+
def process_response(self, response):
57+
return _DocumentReportList(
58+
**super().process_response(response)["submissionsLog"]
59+
).submissions

indico/queries/submission.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
from operator import eq, ne
55
from typing import Dict, List, Union
66

7-
from indico.client.request import GraphQLRequest, RequestChain
7+
from indico.client.request import GraphQLRequest, RequestChain, PagedRequest
88
from indico.errors import IndicoInputError, IndicoTimeoutError
99
from indico.filters import SubmissionFilter
1010
from indico.queries import JobStatus
1111
from indico.types import Job, Submission
1212
from indico.types.submission import VALID_SUBMISSION_STATUSES
1313

1414

15-
class ListSubmissions(GraphQLRequest):
15+
class ListSubmissions(PagedRequest):
1616
"""
1717
List all Submissions visible to the authenticated user by most recent.
18+
Supports pagination (limit becomes page_size)
1819
1920
Options:
2021
submission_ids (List[int]): Submission ids to filter by
@@ -26,6 +27,7 @@ class ListSubmissions(GraphQLRequest):
2627
2728
Returns:
2829
List[Submission]: All the found Submission objects
30+
If paginated, yields results one at a time
2931
"""
3032

3133
query = """
@@ -35,7 +37,8 @@ class ListSubmissions(GraphQLRequest):
3537
$filters: SubmissionFilter,
3638
$limit: Int,
3739
$orderBy: SUBMISSION_COLUMN_ENUM,
38-
$desc: Boolean
40+
$desc: Boolean,
41+
$after: Int
3942
4043
){
4144
submissions(
@@ -44,7 +47,8 @@ class ListSubmissions(GraphQLRequest):
4447
filters: $filters,
4548
limit: $limit
4649
orderBy: $orderBy,
47-
desc: $desc
50+
desc: $desc,
51+
after: $after
4852
4953
){
5054
submissions {
@@ -59,6 +63,10 @@ class ListSubmissions(GraphQLRequest):
5963
retrieved
6064
errors
6165
}
66+
pageInfo {
67+
endCursor
68+
hasNextPage
69+
}
6270
}
6371
}
6472
"""

tests/integration/queries/test_workflow.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import io
2-
31
from indico.queries.workflow import GetWorkflow
42
import pytest
53
from pathlib import Path
@@ -248,6 +246,23 @@ def test_list_workflow_submission_retrieved(
248246
assert all([not s.retrieved for s in submissions])
249247
assert submission_id not in [s.id for s in submissions]
250248

249+
def test_list_workflow_submission_paginate(
250+
indico, airlines_dataset, airlines_model_group: ModelGroup
251+
):
252+
client = IndicoClient()
253+
wfs = client.call(ListWorkflows(dataset_ids=[airlines_dataset.id]))
254+
wf = max(wfs, key=lambda w: w.id)
255+
256+
dataset_filepath = str(Path(__file__).parents[1]) + "/data/mock.pdf"
257+
258+
submission_ids = client.call(
259+
WorkflowSubmission(workflow_id=wf.id, files=[dataset_filepath]*5)
260+
)
261+
for sub in client.paginate(ListSubmissions(workflow_ids=[wf.id], limit=3)):
262+
263+
if not submission_ids:
264+
break
265+
assert sub.id == submission_ids.pop() # list is desc by default
251266

252267
def test_workflow_submission_missing_workflow(indico):
253268
client = IndicoClient()

0 commit comments

Comments
 (0)