~bac/charmworld/bug-1257878

« back to all changes in this revision

Viewing changes to charmworld/jobs/github.py

  • Committer: Tarmac
  • Author(s): j.c.sackett
  • Date: 2013-11-18 16:29:57 UTC
  • mfrom: (460.1.11 better-jobs)
  • Revision ID: tarmac-20131118162957-9hmgcrrzinyheezy
Handle some failure modes with better logging.

Approved by Juju Gui Bot, Aaron Bentley.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
from utils import LockHeld
17
17
 
18
18
 
 
19
class GithubRateLimitError(Exception):
 
20
    pass
 
21
 
 
22
 
19
23
def make_github_request(endpoint_name, repo_name=None):
20
24
    if endpoint_name == 'repos':
21
25
        url = 'https://api.github.com/users/charms/repos'
24
28
            raise ValueError('repo_name cannot be None for pull requests')
25
29
        url = 'https://api.github.com/repos/charms/%s/pulls' % repo_name
26
30
    r = requests.get(url)
 
31
    if int(r.headers.get('x-ratelimit-remaining', 1)) == 0:
 
32
        raise GithubRateLimitError('Github ratelimit exceeded')
27
33
    return r.json()
28
34
 
29
35
 
77
83
    conn = pymongo.Connection(MONGO_URL, safe=True)
78
84
    db = conn['juju']
79
85
    settings = get_ini()
80
 
    charm_repos = get_charm_repos(log)
81
 
    pull_requests = get_pull_requests(charm_repos, log)
 
86
    try:
 
87
        charm_repos = get_charm_repos(log)
 
88
    except (requests.ConnectionError, GithubRateLimitError) as e:
 
89
        log.error("Couldn't complete request for repos: %s" % e)
 
90
        return
 
91
    try:
 
92
        pull_requests = get_pull_requests(charm_repos, log)
 
93
    except (requests.ConnectionError, GithubRateLimitError) as e:
 
94
        log.error("Couldn't complete request for pull-requests: %s" % e)
 
95
        return
82
96
    entries = create_entries_from_pull_requests(pull_requests)
83
97
    try:
84
98
        with lock('github',