Retry `hg pull` from canonical (BitBucket) repos if it fails
...in the first instance. It seems that BitBucket is either laggy
or has some threshold policy causing `HTTP 410: Gone` when pulling
during CI checkout.
A desperate atempt to workaround this error is to wait 30-130 seconds
and retry. If it fails again, retry once more before giving up. Sigh,
what a hack!
--- a/rakelib/scm.rb Thu Feb 28 11:15:57 2019 +0000
+++ b/rakelib/scm.rb Wed Jun 12 07:50:32 2019 +0000
@@ -152,7 +152,23 @@
paths['canonical'] = "#{repository.canonical}/#{directory.gsub('/', separator)}"
hg.paths = paths
end
- hg.pull('canonical')
+
+ begin
+ hg.pull('canonical') if repository.canonical
+ rescue Exception
+ delay = 30 + rand * 100
+ info("Will retry after #{delay}...")
+ sleep(delay)
+ begin
+ hg.pull('canonical')
+ rescue Exception
+ delay = 30 + rand * 100
+ info("Will retry after #{delay}...")
+ sleep(delay)
+ hg.pull('canonical')
+ end
+ end
+
# If revision is not specified, then look for an active bookmark
# and update to it. If no bookmark is active, then look for bookmark
# `master`. If it exist, then update to `master`. If it
@@ -165,7 +181,7 @@
unless revision
bookmarks = hg.bookmarks(branch)
if bookmarks.has_key? BUILD_BRANCH
- revision = BUILD_BRANCH
+ revision = BUILD_BRANCH
elsif bookmarks.has_key? 'master'
revision = 'master'
else
@@ -283,7 +299,23 @@
hg.pull('staging') if repository.staging
hg.pull('upstream') if repository.upstream
- hg.pull('canonical') if repository.canonical
+
+ begin
+ hg.pull('canonical') if repository.canonical
+ rescue Exception
+ delay = 30 + rand * 100
+ info("Will retry after #{delay}...")
+ sleep(delay)
+ begin
+ hg.pull('canonical')
+ rescue Exception
+ delay = 30 + rand * 100
+ info("Will retry after #{delay}...")
+ sleep(delay)
+ hg.pull('canonical')
+ end
+ end
+
# If revision is not specified, then look for bookmark
# `master`. If it exist, then check out `master`. If it
# does not, then checkout tip or throw an error.
@@ -293,7 +325,7 @@
unless revision
bookmarks = hg.bookmarks(branch)
if bookmarks.has_key? BUILD_BRANCH
- revision = BUILD_BRANCH
+ revision = BUILD_BRANCH
elsif bookmarks.has_key? 'master'
revision = 'master'
else