Skip to content

Only check for new version once every 24 hours#151

Merged
mislav merged 6 commits intomasterfrom
less-aggressive-checking
Dec 13, 2019
Merged

Only check for new version once every 24 hours#151
mislav merged 6 commits intomasterfrom
less-aggressive-checking

Conversation

@probablycorey
Copy link
Copy Markdown
Contributor

This PR makes sure the update notifier doesn't check for new releases too often. It does this by storing the latest version, and the last time we checked for the latest version in .config/gh/state.yml

- Check if version hasn’t been checked in 24 hours
**if no**	
	- Store latest version in state.yml
	- store last time version in in state.yml
- Grab stored version
- If stored version is more than current version, show alert

Closes #145

@probablycorey probablycorey self-assigned this Dec 12, 2019

repo := updaterEnabled
return update.CheckForUpdate(client, repo, currentVersion)
stateFilePath, err := homedir.Expand("~/.config/gh/state.yml")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't like how this file and the config file have knowledge of this directory in separate places, maybe the config directory should be a public method in the config package?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good call, this path is already referenced from at least 3 places around the codebase and we might benefit from moving things into a config package to clean it up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I started to do this in this PR, but it got a little complicated. So I'm going to open a follow up PR to do this.

if err != nil {
return err
}
ioutil.WriteFile(stateFilePath, content, 0600)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we add error handling here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a good question. Errors from the updater are ignored (line 22 in main.go) so errors aren't going to help us much. We want the updater to be mostly silent, but because of this it will fail silently. I haven't been able to come up with a good solution yet.


repo := updaterEnabled
return update.CheckForUpdate(client, repo, currentVersion)
stateFilePath, err := homedir.Expand("~/.config/gh/state.yml")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good call, this path is already referenced from at least 3 places around the codebase and we might benefit from moving things into a config package to clean it up.

- non-existent file simply returns an error
- corrupt file (e.g. YAML unmarshal error) also returns an error
- if there were errors, just check for new release normally instead of aborting
@mislav
Copy link
Copy Markdown
Contributor

mislav commented Dec 13, 2019

@probablycorey I'm proceeding with this because 1) code looks great, good job! 2) followup items (such as extracting config logic) can be easily done in separate PRs; and 3) I want to get this in the bugfix release that I will likely cut within the next hour, and I'm assuming you won't be at work yet at that time. 🙇

Ref. #99

@mislav mislav merged commit 7c611bf into master Dec 13, 2019
@mislav mislav deleted the less-aggressive-checking branch December 13, 2019 16:11
mislav added a commit that referenced this pull request Sep 28, 2021
Wrap errors using "%w" instead of "%v"
cchristous pushed a commit to cchristous/cli that referenced this pull request Feb 28, 2026
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.

Ensure that update notifier doesn't check for new releases too often

2 participants