Ejemplo n.º 1
0
 def _refresh(self):
     # Refresh every 5 minutes
     if time.time() - self._last_refresh > 300:
         try:
             log.info("Loading masters from %s", self.masters_url)
             self.masters = json.load(urllib.urlopen(self.masters_url))
             log.info("Loading branches from %s", self.branches_url)
             self.branches = json.load(urllib.urlopen(self.branches_url))
             self._last_refresh = time.time()
         except:
             log.exception("Couldn't load data; using old ones")
Ejemplo n.º 2
0
 def _refresh(self):
     # Refresh every 5 minutes
     if time.time() - self._last_refresh > 300:
         try:
             log.info("Loading masters from %s", self.masters_url)
             self.masters = json.load(urllib2.urlopen(self.masters_url, timeout=30))
             log.info("Loading branches from %s", self.branches_url)
             self.branches = json.load(urllib2.urlopen(self.branches_url, timeout=30))
             self._last_refresh = time.time()
         except:
             log.exception("Couldn't load data; using old ones")
Ejemplo n.º 3
0
def get_masters():
    global _masters, _last_master_check, _masters_by_dbname, _masters_pools

    now = time.time()

    if now - _last_master_check < _masters_cache_timeout:
        return _masters

    masters_url = app_globals.masters_url
    log.info("Fetching master list from %s", masters_url)
    try:
        masters = json.load(urllib.urlopen(masters_url))
        _masters = masters
    except:
        log.exception("Error loading masters json; using old list")
        return _masters

    _last_master_check = now
    _masters_by_dbname = {}
    _masters_pools = {BUILDPOOL: [], TRYBUILDPOOL: [], TESTPOOL: []}
    for m in _masters:
        _masters_by_dbname[m['db_name']] = m
        pool = ROLE_MASTERS_POOLS.get(m['role'], None)
        if pool in _masters_pools:
            _masters_pools[pool].append(m['db_name'])
    return _masters
def get_masters():
    global _masters, _last_master_check, _masters_by_dbname, _masters_pools

    now = time.time()

    if now - _last_master_check < _masters_cache_timeout:
        return _masters

    masters_url = app_globals.masters_url
    log.info("Fetching master list from %s", masters_url)
    try:
        masters = json.load(urllib2.urlopen(masters_url, timeout=30))
        _masters = masters
    except:
        log.exception("Error loading masters json; using old list")
        return _masters

    _last_master_check = now
    _masters_by_dbname = {}
    _masters_pools = {BUILDPOOL: [], TRYBUILDPOOL: [], TESTPOOL: []}
    for m in _masters:
        _masters_by_dbname[m['db_name']] = m
        pool = ROLE_MASTERS_POOLS.get(m['role'], None)
        if pool in _masters_pools:
            _masters_pools[pool].append(m['db_name'])
    return _masters
Ejemplo n.º 5
0
def get_branches():
    global _branches, _last_branches_check

    now = time.time()
    if now - _last_branches_check < _last_branches_timeout:
        return _branches

    branches_url = app_globals.branches_url
    log.info("Fetching branches list from %s", branches_url)
    try:
        if branches_url.startswith('TEST:'):
            branches = json.load(open(branches_url.split(':')[1]))
        else:
            branches = json.load(urllib.urlopen(branches_url))
        _branches = branches
        _last_branches_check = now
    except:
        log.exception("Error loading branches json; using old list")

    return _branches
def get_branches():
    global _branches, _last_branches_check

    now = time.time()
    if now - _last_branches_check < _last_branches_timeout:
        return _branches

    branches_url = app_globals.branches_url
    log.info("Fetching branches list from %s", branches_url)
    try:
        if branches_url.startswith('TEST:'):
            branches = json.load(open(branches_url.split(':')[1]))
        else:
            branches = json.load(urllib2.urlopen(branches_url, timeout=30))
        _branches = branches
        _last_branches_check = now
    except:
        log.exception("Error loading branches json; using old list")

    return _branches
Ejemplo n.º 7
0
 def test_branches(self):
     response = self.app.get(url('branches', format='json')).json
     self.assertEquals(response, json.load(open('branches-test.json')))