Merge lp:~milo/linaro-patchmetrics/bug1012538 into lp:linaro-patchmetrics

Proposed by Milo Casagrande
Status: Merged
Merged at revision: 370
Proposed branch: lp:~milo/linaro-patchmetrics/bug1012538
Merge into: lp:linaro-patchmetrics
Diff against target: 70 lines (+31/-10)
1 file modified
apps/patchmetrics/utils.py (+31/-10)
To merge this branch: bzr merge lp:~milo/linaro-patchmetrics/bug1012538
Reviewer Review Type Date Requested Status
Deepti B. Kalakeri (community) Approve
Review via email: mp+112087@code.launchpad.net

Description of the change

Hi,

I'm proposing the following merge in order to address, if not completely, the 503 HTTP error we sometimes get from Launchpad. Since we cannot make anything else about it, I added a retry loop with a sleep timeout in order to have a little bit of time between one retry and the other.

At the moment, the retries are fixed at a maximum of 3, and the timeout is set to 30 seconds.

To post a comment you must log in.
Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :

I guess the bug https://bugs.launchpad.net/linaro-patchmetrics/+bug/967290 mentioned in the following
code is not fixed yet . Have you tested this, that email parsing code does not insert any invalid email address in the first place ?

69 + else:
70 + # XXX We should not encounter bad email addresses.
71 + #https://bugs.launchpad.net/linaro-patchmetrics/+bug/967290
72 + person = None # Launchpad lookup failed.
73 + logger.warning("Launchpad rejected email lookup and "
74 + "returned HTTPError. Offending email "
75 + "address: %s" % email)

If the above code has been tested for bug https://bugs.launchpad.net/linaro-patchmetrics/+bug/967290 to be fixed, then everything looks good +1.
Also, use FIXME: instead of XXX when you merge this code.

Revision history for this message
Milo Casagrande (milo) wrote :

Hi Deepti,

now that you point it out, no, this merge request has not been tested WRT bug 967290, and the logic of that part needs to be rethought.

Thanks.

366. By Milo Casagrande

Fixed retries logic.

Revision history for this message
Milo Casagrande (milo) wrote :

Hi,

the latest push should fix the logic of that part, basically reimplementing it as it was before, with two different try statements.

Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :

+1 Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'apps/patchmetrics/utils.py'
--- apps/patchmetrics/utils.py 2012-04-03 13:16:22 +0000
+++ apps/patchmetrics/utils.py 2012-06-29 15:50:27 +0000
@@ -6,6 +6,7 @@
6from patchwork.models import Person6from patchwork.models import Person
7from patchmetrics.models import Team7from patchmetrics.models import Team
8import urllib28import urllib2
9import time
9from xml.dom.minidom import parseString10from xml.dom.minidom import parseString
10from lazr.restfulclient.errors import HTTPError11from lazr.restfulclient.errors import HTTPError
1112
@@ -13,6 +14,11 @@
13logging.basicConfig()14logging.basicConfig()
14logger = logging.getLogger()15logger = logging.getLogger()
1516
17# Time in seconds to wait before performing another HTTP request.
18REQUEST_WAIT = 30
19# Max retries if something goes wrong, but it can be recoverd just retrying.
20MAX_RETRIES = 3
21
1622
17def sync_memberships(memberships):23def sync_memberships(memberships):
18 """Make sure the given memberships are represented in our database.24 """Make sure the given memberships are represented in our database.
@@ -151,23 +157,38 @@
151 try:157 try:
152 person = get_lp_person_by_email(lp, email)158 person = get_lp_person_by_email(lp, email)
153 except HTTPError:159 except HTTPError:
154 # XXX We should not encounter bad email addresses.160 # FIXME We should not encounter bad email addresses.
155 # https://bugs.launchpad.net/linaro-patchmetrics/+bug/967290161 # https://bugs.launchpad.net/linaro-patchmetrics/+bug/967290
156 person = None # Launchpad lookup failed.162 person = None # Launchpad lookup failed.
157 logger.warning("Launchpad rejected email lookup and returned "163 logger.warning("Launchpad rejected email lookup and returned "
158 "HTTPError. Offending email address: %s" % email)164 "HTTPError. Offending email address: %s" % email)
159165
160 if not person:166 if not person:
161 continue # No Launchpad entry for this person.167 # No Launchpad entry for this person.
162 member_of = is_member(person, teams)168 continue
163 for team in member_of:169
164 if not team in memberships:170 # Counter for the retries to perform in case of an HTTP error 503.
165 memberships[team] = {}171 retries_count = 0
166172 while True:
167 memberships[team][person] = [email]173 try:
174 member_of = is_member(person, teams)
175 for team in member_of:
176 if not team in memberships:
177 memberships[team] = {}
178
179 memberships[team][person] = [email]
180 except HTTPError, ex:
181 # We should not get an error 503 from Launchpad.
182 # https://bugs.launchpad.net/linaro-patchmetrics/+bug/1012538
183 if ex.code == 503 and retries_count < MAX_RETRIES:
184 retries_count += 1
185 time.sleep(REQUEST_WAIT)
186 continue
187 else:
188 raise(ex)
189 break
168190
169 sync_memberships(memberships)191 sync_memberships(memberships)
170
171 sync_openid_urls()192 sync_openid_urls()
172193
173194

Subscribers

People subscribed via source and target branches