コード例 #1
0
 def instantiate_other_test(self):
     """Passing anything other than `memory`, `jdg` or `infinispan` will
     create a `MemoryCache`
     """
     os.environ['CACHE_TYPE'] = 'foobar'
     cache = factory()
     assert_true(isinstance(cache, MemoryCache))
コード例 #2
0
 def instantiate_memory_default_test(self):
     """If no environment data is provided for the cache backend,
     use the memory store
     """
     os.environ['CACHE_TYPE'] = ''
     cache = factory()
     assert_true(isinstance(cache, MemoryCache))
コード例 #3
0
ファイル: app.py プロジェクト: sophwats/jiminy-predictor
def main():
    """start the http service"""

    # acquire logger
    logger = get_logger()

    # add the ALS type conversion Scala helper jar
    os.environ[
        'PYSPARK_SUBMIT_ARGS'] = '--jars ./libs/spark-als-serializer_2.11-0.2.jar pyspark-shell'  # noqa: E501

    # create the flask app object
    app = flask.Flask(__name__)
    # change this value for production environments
    app.config['SECRET_KEY'] = 'secret!'

    # queues for ipc with the prediction process
    request_q = mp.Queue()
    response_q = mp.Queue()

    # start the prediction process
    process = mp.Process(target=predictions.loop, args=(request_q, response_q))
    process.start()

    # waiting for processing loop to become active
    response_q.get()

    # initialize a cache store
    # (uses environment variables for connection information)
    logger.debug("Initializing cache")
    storage = caches.factory()

    # create and start the cache updater thread
    thread = t.Thread(target=caches.updater, args=(response_q, storage))
    thread.start()

    # configure routes and start the service
    app.add_url_rule('/', view_func=views.ServerInfo.as_view('server'))
    app.add_url_rule('/predictions/ratings',
                     view_func=views.PredictionsRatings.as_view(
                         'rating_prediction', storage, request_q))
    app.add_url_rule('/predictions/ratings/<string:p_id>',
                     view_func=views.PredictionDetail.as_view(
                         'rating_predictions', storage))

    app.add_url_rule('/predictions/ranks',
                     view_func=views.PredictionsRanks.as_view(
                         'rank_prediction', storage, request_q))

    app.add_url_rule('/predictions/ranks/<string:p_id>',
                     view_func=views.PredictionDetail.as_view(
                         'rank_predictions', storage))

    app.run(host='0.0.0.0', port=8080)
    request_q.put('stop')
    response_q.put('stop')
コード例 #4
0
 def instantiate_jdg_test(self):
     """Passing the 'jdg' type should instantiate a `InfinispanCache`
     """
     os.environ['CACHE_TYPE'] = 'jdg'
     cache = factory()
     assert_true(isinstance(cache, InfinispanCache))
コード例 #5
0
 def instantiate_memory_test(self):
     """Passing the 'memory' type should instantiate a `MemoryCache`
     """
     os.environ['CACHE_TYPE'] = 'memory'
     cache = factory()
     assert_true(isinstance(cache, MemoryCache))