-
Notifications
You must be signed in to change notification settings - Fork 56
fix: add pagination to 'submit all' to process all datasets #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dsanchezmatilla
wants to merge
2
commits into
ckan:master
Choose a base branch
from
dsanchezmatilla:fix/submit-all-pagination
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,14 +46,27 @@ def _submit_all(self, sync=False, queue=None): | |
# submit every package | ||
# for each package in the package list, | ||
# submit each resource w/ _submit_package | ||
package_list = tk.get_action('package_search')( | ||
{'ignore_auth': True}, {'include_private': True, 'rows': 1000}) | ||
package_list = [pkg['id'] for pkg in package_list['results']] | ||
arguments = {'include_private': True, 'start': 0, 'rows': 10} | ||
|
||
response = tk.get_action('package_search')({'ignore_auth': True}, {'include_private': True}) | ||
num_pages = (response['count'] + 999) // 1000 | ||
arguments['rows'] = 1000 | ||
package_list = [] | ||
|
||
for page in range(0, num_pages): | ||
paged_response = tk.get_action('package_search')({'ignore_auth': True}, arguments) | ||
package_list.extend([pkg['id'] for pkg in paged_response['results']]) | ||
arguments['start'] += 1000 | ||
|
||
print('Processing %d datasets' % len(package_list)) | ||
user = tk.get_action('get_site_user')( | ||
{'ignore_auth': True}, {}) | ||
for p_id in package_list: | ||
self._submit_package(p_id, user, indent=2, sync=sync, queue=queue) | ||
check_start = input('This action could take a few minuts depending on the number of DataSets:\nDid you want to start the process? y/N\n') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minuts/minutes |
||
|
||
if check_start == 'y': | ||
user = tk.get_action('get_site_user')({'ignore_auth': True}, {}) | ||
for p_id in package_list: | ||
self._submit_package(p_id, user, indent=2, sync=sync, queue=queue) | ||
else: | ||
print('Submit all process stoped') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stoped/stopped |
||
|
||
def _submit_package(self, pkg_id, user=None, indent=0, sync=False, queue=None): | ||
indentation = ' ' * indent | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Since the whole purpose of pagination is to handle arbitrarily large numbers of datasets, perhaps it would be better to process each batch of 1000 before retrieving the next, rather than assembling a package ID list of arbitrarily large size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on @ThrawnCA input, you could get a total number of packages in the system (without all the data), then ask the question.
If yes, then do the pagination and submit the jobs so you can discard/release memory. This becomes very required when you have over 100,000+ datasets and working on small containers.