Skip to content
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

Follow pagination and implement rate throttling #42

Merged
merged 5 commits into from
Feb 12, 2023

Conversation

jacobthemyth
Copy link
Contributor

I was having a problem with images not getting deleted. It turns out the
maximum page size is now 100, down from 500. Since the application I'm
using this for consistently has more than 100 images that don't meet the
delete criteria and they're in the first page, the action would never
fetch the images that needed to be deleted.

This uses the Hypermedia link header
(https://docs.github.com/en/rest/overview/resources-in-the-rest-api#hypermedia)
to traverse all pages. This worked well, but I hit both primary and
secondary rate limits trying to delete all my old images, so I also
added a function to handle rate limiting.

This still needs tests, documentation, and probably some error handling
and print statements, but I wanted to open a PR to see whether you're
okay with this approach and would consider merging it before I spend on
these details.

@jacobthemyth jacobthemyth force-pushed the pagination-and-rate-limit branch from e316d4c to b51e821 Compare August 24, 2022 23:20
@jacobthemyth jacobthemyth force-pushed the pagination-and-rate-limit branch from 2c98be2 to e7166cc Compare August 24, 2022 23:33
@codecov
Copy link

codecov bot commented Aug 24, 2022

Codecov Report

Merging #42 (2ff9ce0) into main (cc57103) will increase coverage by 0.24%.
The diff coverage is 75.00%.

❗ Current head 2ff9ce0 differs from pull request most recent head 108bfb6. Consider uploading reports for the commit 108bfb6 to get more accurate results

@@            Coverage Diff             @@
##             main      #42      +/-   ##
==========================================
+ Coverage   89.84%   90.09%   +0.24%     
==========================================
  Files           1        1              
  Lines         197      222      +25     
  Branches       46       51       +5     
==========================================
+ Hits          177      200      +23     
- Misses         14       16       +2     
  Partials        6        6              
Impacted Files Coverage Δ
main.py 90.09% <75.00%> (+0.24%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@sondrelg sondrelg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traversing backwards and handling rate limits both sound like great ideas, and the current implementation looks good to me at first glance 👏 Let me know when you've added docs and tests, and I'll review right away 👍

main.py Outdated Show resolved Hide resolved
Co-authored-by: Sondre Lillebø Gundersen <[email protected]>
Copy link
Contributor

@lukasz-mitka lukasz-mitka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add pagination for list_packages and list_org_packages. Same issue is present there.
https://github.com/snok/container-retention-policy/pull/42/files#diff-b10564ab7d2c520cdd0243874879fb0a782862c3c902ab535faabe57d5a505e1R95

@jacobthemyth
Copy link
Contributor Author

@lukasz-mitka sure, can do. It will be a few more days until I have time to finish this, but will include those functions.

@sondrelg
Copy link
Member

sondrelg commented Oct 6, 2022

Any updates here @systemist? 🙂

@den-is
Copy link
Contributor

den-is commented Oct 18, 2022

I've encountered the same issue
One ugly configured repository has a Package with 10k untagged and 2k tagged images under it! 🙀
This update and work will be highly appreciated! 🙇
Unfortunately, I lack python asyncio apps development skills.

@lukasz-mitka
Copy link
Contributor

@den-is if you're in a hurry you can try using this this PR directly

uses: systemist/container-retention-policy@pagination-and-rate-limit

Disclaimer: I didn't test it :)

@sondrelg sondrelg mentioned this pull request Dec 15, 2022
@sondrelg
Copy link
Member

@systemist are you still planning on finishing this?

@sondrelg
Copy link
Member

sondrelg commented Jan 18, 2023

Does anyone else fancy finishing the PR? It's 90% ready if I recall correctly?

Would be nice to merge and bump major versions this week or next if possible.

@sondrelg
Copy link
Member

I'll merge this, try to add tests and docs, then upgrade today hopefully 🙂

@sondrelg sondrelg marked this pull request as ready for review February 12, 2023 09:42
@sondrelg sondrelg merged commit 270d72c into snok:main Feb 12, 2023
@sondrelg
Copy link
Member

The main branch should now be up to date. I've added some tests, and I've added pagination support to the package fetching.

Does anyone have a repo with a package count high enough to test if the main branch currently works? Would be nice to get at least one confirmation before we bump major version, if anyone here is free to try 🙇

@lukasz-mitka
Copy link
Contributor

lukasz-mitka commented Feb 14, 2023

@sondrelg Thank you for finishing this!
It's working fine in my setup (>>100 versions)

Found the bug though. Step outputs didn't get set: #56

@sondrelg
Copy link
Member

Thanks for testing! I'll release a new version today then hopefully 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants