コード例 #1
0
def test_server():
    base_url = 'http://{host}:{port}'.format(**sc.config['test'])
    attempts = 0
    max_attempts = 2
    time.sleep(5)
    logger.info('Now loading test pages to confirm server stability')
    while attempts < max_attempts:
        if attempts != 0:
            time.sleep(10)
        attempts += 1

        try:
            for path in sc.config['test']['paths']:
                url = urllib.parse.urljoin(base_url, path)
                response = urllib.request.urlopen(url)
                logger.info('{} [{}]'.format(url, response.code))
                if response.code == 200:
                    continue
                else:
                    break
            # Success!
            stop(0)

        except urllib.error.URLError as e:
            logger.info('{} : {!s}'.format(url, e))

    logger.error(
        _red_text('Failed to achieve a 200 response for {}'.format(url)))
    stop(1, 'fails to generate HTTP 200 Responses')
コード例 #2
0
def stop(exit_code, msg=None):
    try:
        cherrypy.engine.exit()
        cherrypy.server.stop()
        logger.info('Now shutting down test server on port {}'.format(
            sc.config['test']['port']))
        time.sleep(1)
    except NameError:
        pass
    time.sleep(0.5)
    if exit_code == 0:
        logger.info(
            _green_text('''\
Test Server returns HTTP 200 Responses. Production should be good to go.'''))
        save_last_good()
    else:
        logger.error(
            _red_text('''\
CRITICAL PROBLEM! [AKA Bad Dev, Don't break the server!]

A test instance of the server using the current branch code
{}. This is a critical problem causing
all or much of the site to generate error pages instead of the intended
pages.
Please attempt to reproduce this problem on a development server
or the staging server.
The production server has not been restarted and is still running the
pre-updated code. It should still be functioning.
However it may be in an inconsistent state or generating errors.
If you are unable to fix the problem, please inform the primary server
administrator that this problem has occurred.
This warning should not be bypassed as if the production server is 
restarted now it will almost certainly be severely broken.'''.format(msg)))
    os._exit(exit_code)
コード例 #3
0
def stop(exit_code, msg=None):
    try:
        cherrypy.engine.exit()
        cherrypy.server.stop()
        logger.info('Now shutting down test server on port {}'.format(sc.config['test']['port']))
        time.sleep(1)
    except NameError:
        pass
    time.sleep(0.5)
    if exit_code == 0:
        logger.info(_green_text('''\
Test Server returns HTTP 200 Responses. Production should be good to go.'''))
        save_last_good()
    else:
        logger.error(_red_text('''\
CRITICAL PROBLEM! [AKA Bad Dev, Don't break the server!]

A test instance of the server using the current branch code
{}. This is a critical problem causing
all or much of the site to generate error pages instead of the intended
pages.
Please attempt to reproduce this problem on a development server
or the staging server.
The production server has not been restarted and is still running the
pre-updated code. It should still be functioning.
However it may be in an inconsistent state or generating errors.
If you are unable to fix the problem, please inform the primary server
administrator that this problem has occurred.
This warning should not be bypassed as if the production server is 
restarted now it will almost certainly be severely broken.'''.format(msg)))
    os._exit(exit_code)
コード例 #4
0
def test_server():
    base_url = 'http://{host}:{port}'.format(**sc.config['test'])
    attempts = 0
    max_attempts = 2
    time.sleep(5)
    logger.info('Now loading test pages to confirm server stability')
    while attempts < max_attempts:
        if attempts != 0:
            time.sleep(10)
        attempts += 1
        
        try:
            for path in sc.config['test']['paths']:
                url = urllib.parse.urljoin(base_url, path)
                response = urllib.request.urlopen(url)
                logger.info('{} [{}]'.format(url, response.code))
                if response.code == 200:
                    continue
                else:
                    break
            # Success!
            stop(0)
                
        except urllib.error.URLError as e:
            logger.info('{} : {!s}'.format(url, e))
    
    logger.error(_red_text('Failed to achieve a 200 response for {}'.format(url)))
    stop(1, 'fails to generate HTTP 200 Responses')
コード例 #5
0
def update_indexes():
    if not is_available():
        logger.error('Elasticsearch Not Available')
        return
    import sc.search.dicts
    import sc.search.texts
    import sc.search.suttas

    sc.search.dicts.update()
    sc.search.suttas.update()
    sc.search.texts.update()
コード例 #6
0
def update_indexes():
    if not is_available():
        logger.error('Elasticsearch Not Available')
        return
    import sc.search.dicts
    import sc.search.texts
    import sc.search.suttas

    sc.search.dicts.update()
    sc.search.suttas.update()
    sc.search.texts.update()