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
1=== modified file 'apps/patchmetrics/utils.py'
2--- apps/patchmetrics/utils.py 2012-04-03 13:16:22 +0000
3+++ apps/patchmetrics/utils.py 2012-06-29 15:50:27 +0000
4@@ -6,6 +6,7 @@
5 from patchwork.models import Person
6 from patchmetrics.models import Team
7 import urllib2
8+import time
9 from xml.dom.minidom import parseString
10 from lazr.restfulclient.errors import HTTPError
11
12@@ -13,6 +14,11 @@
13 logging.basicConfig()
14 logger = logging.getLogger()
15
16+# Time in seconds to wait before performing another HTTP request.
17+REQUEST_WAIT = 30
18+# Max retries if something goes wrong, but it can be recoverd just retrying.
19+MAX_RETRIES = 3
20+
21
22 def sync_memberships(memberships):
23 """Make sure the given memberships are represented in our database.
24@@ -151,23 +157,38 @@
25 try:
26 person = get_lp_person_by_email(lp, email)
27 except HTTPError:
28- # XXX We should not encounter bad email addresses.
29+ # FIXME We should not encounter bad email addresses.
30 # https://bugs.launchpad.net/linaro-patchmetrics/+bug/967290
31 person = None # Launchpad lookup failed.
32 logger.warning("Launchpad rejected email lookup and returned "
33- "HTTPError. Offending email address: %s" % email)
34+ "HTTPError. Offending email address: %s" % email)
35
36 if not person:
37- continue # No Launchpad entry for this person.
38- member_of = is_member(person, teams)
39- for team in member_of:
40- if not team in memberships:
41- memberships[team] = {}
42-
43- memberships[team][person] = [email]
44+ # No Launchpad entry for this person.
45+ continue
46+
47+ # Counter for the retries to perform in case of an HTTP error 503.
48+ retries_count = 0
49+ while True:
50+ try:
51+ member_of = is_member(person, teams)
52+ for team in member_of:
53+ if not team in memberships:
54+ memberships[team] = {}
55+
56+ memberships[team][person] = [email]
57+ except HTTPError, ex:
58+ # We should not get an error 503 from Launchpad.
59+ # https://bugs.launchpad.net/linaro-patchmetrics/+bug/1012538
60+ if ex.code == 503 and retries_count < MAX_RETRIES:
61+ retries_count += 1
62+ time.sleep(REQUEST_WAIT)
63+ continue
64+ else:
65+ raise(ex)
66+ break
67
68 sync_memberships(memberships)
69-
70 sync_openid_urls()
71
72

Subscribers

People subscribed via source and target branches