Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 6cfc19b

Browse files
committed
bot.mirror: fine tune the @curl-data update
1 parent 5408a5b commit 6cfc19b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

bot/plugins/mirror.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def mirror_default(m)
3030

3131
def mirror_monitor(m)
3232
if gs = @curl_data["f"]["report_time"].to_s.match(/^([0-9]{8})-([0-9]{2})([0-9]{2})([0-9]{2})/)
33-
date, h, m, s = gs[1], gs[2], gs[3], gs[4]
34-
offset = Time.now - Time.parse(sprintf("%s %s:%s:%s", date, h, m, s))
33+
date, h, min, s = gs[1], gs[2], gs[3], gs[4]
34+
offset = Time.now - Time.parse(sprintf("%s %s:%s:%s", date, h, min, s))
3535
if offset >= 5400 # 3600 + 1800 aka 1.5 hours
3636
m.reply "!! Warning: Mirror is out-of-sync. Last update is #{offset / 60} minutes ago" \
3737
unless _cache_expired?(:mirror, "cron_warning", :cache_time => 1800)
@@ -45,8 +45,16 @@ def mirror_monitor(m)
4545

4646
# Update data every 0.5 hour
4747
def mirror_cron(m)
48-
return mirror_monitor(m) \
49-
if not _cache_expired?(:mirror, "cron", :cache_time => 1800)
48+
if not _cache_expired?(:mirror, "cron", :cache_time => 1800)
49+
# If @curl_data is good, we just return because we're in cache window
50+
if not @curl_data["f"]["report_time"].to_s.empty?
51+
return mirror_monitor(m)
52+
# Otherwise, we will try to update @curl_data.
53+
# However, we don't that too often. We will try after 10 minutes
54+
elsif not _cache_expired?(:mirror, "cron_retry", :cache_time => 600)
55+
return mirror_monitor(m)
56+
end
57+
end
5058

5159
url = "http://f.archlinuxvn.org/archlinux/status.json"
5260
fpt = "http://mirror-fpt-telecom.fpt.net/archlinux/lastsync"

0 commit comments

Comments
 (0)