howoldis
howoldis copied to clipboard
[PoC/RFC] Switch to background updates, pull channel info via GitHub API.
Ended up writing this little experiment and figured might as well share.
This switches the update process to an updater running on a background thread updating an in-memory cache of channel information on a fixed interval (in the current implementation every 60 seconds).
As previously the list of channels is retrieved from https://nixos.org/channels/ however the freshness information is retrieved via GitHub API. For each channel a lookup is performed against its respective branch on NixOS/nixpkgs and NixOS/nixpkgs-channels and the freshness is computed as the time difference between the latest commits on the branches.
If GITHUB_TOKEN
env variable is set the requests to GitHub will be authenticated which increases the number of requests per hour that can be performed to the API, and thus frequency of updates.
At the moment the code does few more requests than it strictly needs but I haven't looked into optimising that part (which would probably complicate the code even more). The are probably few more things to tweak like the update interval, retry frequency on failures, etc.
(Sorry for the large diff, applied hindent out of habit so there is a fair amount of purely formatting changes :/).
@madjar what do you think? :)
That sounds reasonable. I already have a credit card in heroku, and I'm okay with the process being killed after 30 minutes of inactivity.
I'll try to make some time to merge this and configure the needed env variables.
Aside from the design / wording changes I wonder how frequently this should poll for updates. At the moment I arbitrarily picked 1 minute interval but perhaps that seems like a bit much? We would need to consider the amount of requests vs GH API rate limits.
Also if anyone wants to have a look but doesn't want to build locally I'm running a demo based off this branch at https://howoldis-gh-bg.herokuapp.com (hope that's OK).
I think 30min should be fine to start with. Maybe add some text on the page to say data refreshes every 30min.
Also add timestamp of last update, maybe in footer?
Howoldis howoldis?