diff --git a/lib/maptool/updater.rb b/lib/maptool/updater.rb index 8ab6056..1a67761 100644 --- a/lib/maptool/updater.rb +++ b/lib/maptool/updater.rb @@ -10,6 +10,7 @@ module Maptool # back in data/update/status.json. module Updater CHECK_EVERY_S = 600 + RETRY_AFTER_S = 60 # a check that failed (offline, a commit CI hasn't seen yet) MUTEX = Mutex.new def self.dir(data_dir) @@ -20,11 +21,17 @@ module Maptool # CHECK_EVERY_S; nil while Gitea can't be reached (no internet on the road). def self.latest(gitea_url, repo, fetch: method(:get_json)) MUTEX.synchronize do - return @latest if @checked_at && Time.now.to_f - @checked_at < CHECK_EVERY_S + # CI still running (or the check failed): sooner, so the button shows when it's through + return @latest if @checked_at && Time.now.to_f - @checked_at < (@latest&.dig(:ci) == "success" ? CHECK_EVERY_S : RETRY_AFTER_S) @checked_at = Time.now.to_f sha = fetch.call("#{gitea_url}/api/v1/repos/#{repo}/branches/main").dig("commit", "id") - @latest = { sha: sha, ci: fetch.call("#{gitea_url}/api/v1/repos/#{repo}/commits/#{sha}/status")["state"] } + ci = begin + fetch.call("#{gitea_url}/api/v1/repos/#{repo}/commits/#{sha}/status")["state"] + rescue StandardError + nil # no status yet: not offered, asked again in a minute + end + @latest = ci ? { sha: sha, ci: ci } : nil rescue StandardError @latest = nil end