Update check: a failed one or CI still running is asked again after a minute, not cached for 10
CI / check (push) Successful in 22s
CI / deploy (push) Successful in 18s

This commit is contained in:
randy committed 2026-11-30 19:26:32 +01:00
1 parent e03e426eb6
commit e7f3b91337
1 file changed
+9 -2
+9 -2
View File
@@ -10,6 +10,7 @@ module Maptool
# back in data/update/status.json. # back in data/update/status.json.
module Updater module Updater
CHECK_EVERY_S = 600 CHECK_EVERY_S = 600
RETRY_AFTER_S = 60 # a check that failed (offline, a commit CI hasn't seen yet)
MUTEX = Mutex.new MUTEX = Mutex.new
def self.dir(data_dir) 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). # 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)) def self.latest(gitea_url, repo, fetch: method(:get_json))
MUTEX.synchronize do 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 @checked_at = Time.now.to_f
sha = fetch.call("#{gitea_url}/api/v1/repos/#{repo}/branches/main").dig("commit", "id") 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 rescue StandardError
@latest = nil @latest = nil
end end