Exemple #1
0
class BaseApp(object):

    def __init__(self, config=None, debug=False, main_loop=None, configure=True):
        self.config = config
        self.main_loop = main_loop
        self.storage = None
        self.project_keys = {}
        self.processed_items = 0
        self.ignored_items = 0
        self.last_requests = []
        self.average_request_time = None
        self.percentile_request_time = None
        self.cache = None
        self.project_loader = ProjectLoader(self.config)
        if configure:
            self.configure(debug=debug)

    def configure(self, debug=False):
        if debug:
            self.config.NUMBER_OF_FORKS = 1
        self.project_loader.log_info()

        cache_class = get_class(self.config.CACHE_IMPLEMENTATION_CLASS)
        self.cache = cache_class(self)

        storage_class = get_class(self.config.STORAGE)
        self.storage = storage_class(self)

        projects_update_task = ProjectsUpdateTask(self, self.main_loop)
        projects_update_task.update()
        projects_update_task.start()

        send_to_sentry_task = SendToSentryTask(self, self.main_loop)
        send_to_sentry_task.update()
        send_to_sentry_task.start()

        AsyncHTTPClient.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")

    def get_handlers(self):
        return [
            url(r'/api/(?P<project_id>\d+)/store/', RouterHandler, name="router"),
            # Deprecated
            url(r'/api/store/', OldRouterHandler, name="router_post"),
            #/Deprecated
            url(r'/count', CountHandler, name="count"),
            url(r'/healthcheck(?:/|\.html)?', HealthCheckHandler, name="healthcheck"),
        ]

    def load_project_keys(self):
        self.project_keys = self.project_loader.get_project_keys()
        return self.project_keys
Exemple #2
0
def test_project_keys_without_mysql():
    config = Config()
    config.PROJECT_KEYS = [
        (1, "public1", "secret1"),
        (2, "public2", "secret2"),
        (1, "public1.2", "secret1.2"),
    ]
    config.MYSQL_HOST = None
    project_loader = ProjectLoader(config)
    project_keys = project_loader.get_project_keys()
    expect(project_keys).to_equal({
        1: {"public_key": ["public1", "public1.2"], "secret_key": ["secret1", "secret1.2"]},
        2: {"public_key": ["public2"], "secret_key": ["secret2"]},
    })
Exemple #3
0
def test_project_keys_without_db():
    config = Config()
    config.PROJECT_KEYS = [
        (1, "public1", "secret1"),
        (2, "public2", "secret2"),
        (1, "public1.2", "secret1.2"),
    ]
    config.DB_HOST = None
    project_loader = ProjectLoader(config)
    project_keys = project_loader.get_project_keys()
    expect(project_keys).to_equal({
        1: {
            "public_key": ["public1", "public1.2"],
            "secret_key": ["secret1", "secret1.2"]
        },
        2: {
            "public_key": ["public2"],
            "secret_key": ["secret2"]
        },
    })