Merge lp:~facundo/lalita/hal-retry into lp:~verterok/lalita/hal

Proposed by Facundo Batista
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: 164
Merged at revision: 165
Proposed branch: lp:~facundo/lalita/hal-retry
Merge into: lp:~verterok/lalita/hal
Diff against target: 51 lines (+25/-4)
1 file modified
lalita/plugins/launchpad.py (+25/-4)
To merge this branch: bzr merge lp:~facundo/lalita/hal-retry
Reviewer Review Type Date Requested Status
Guillermo Gonzalez Approve
Review via email: mp+160755@code.launchpad.net

Commit message

Retry when getting errors from LP.

Description of the change

Retry when getting errors from LP.

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lalita/plugins/launchpad.py'
2--- lalita/plugins/launchpad.py 2012-09-21 19:32:08 +0000
3+++ lalita/plugins/launchpad.py 2013-04-24 20:03:26 +0000
4@@ -353,12 +353,33 @@
5 format_age(c.date_created),
6 c.registrant.name)
7
8+ def iter_project_candidates(self, show, projects, condition):
9+ """Get the candidates per project."""
10+ for p in projects:
11+ self.logger.debug('fetching landing candidates for %r', p)
12+ attempt = 0
13+ while attempt < 3:
14+ attempt += 1
15+ try:
16+ candidates = self.iter_candidates_project(p, condition)
17+ except lazr_errors.HTTPError, err:
18+ resp = err.response
19+ error_msg = "(%s) %s" % (resp['status'],
20+ getattr(resp, 'reason', None))
21+ self.logger.debug("Error getting candidates for %r (%d°):"
22+ " %s", p, attempt, error_msg)
23+ else:
24+ for c in candidates:
25+ yield c
26+ break
27+ else:
28+ show("Error when trying to get info for %r: %s", p, error_msg)
29+
30 @require_launchpad
31 def show_candidates(self, channel, projects, user=None):
32 """ fetch the landing candidates and call d.callback. """
33 show = functools.partial(reactor.callFromThread,
34 self._show_candidates, channel)
35- candidates_count = 0
36 pending = False
37 condition = self.config.get('filters', {}).get(channel)
38 if condition:
39@@ -370,9 +391,9 @@
40 else:
41 self.logger.debug('fetching landing candidates: projects: %s - '
42 'condition: %s', projects, condition)
43- candidates = (c for p in projects \
44- for c in self.iter_candidates_project(
45- p, condition=condition))
46+ candidates = self.iter_project_candidates(show, projects,
47+ condition)
48+
49 for candidate in candidates:
50 if not pending:
51 pending = True

Subscribers

People subscribed via source and target branches