# -*- coding: utf-8 -*- """ manage.py ~~~~~~~~~ Start some long-running worker processes """ from flask.ext.script import Manager import json from receiver import create_app from receiver.core import kafka from receiver.track import track_page_view app = create_app() manager = Manager(app) @manager.command def track(): topic = kafka.topics.get('page_views') consumer = topic.get_simple_consumer() while consumer: line = consumer.consume().value # import pdb; pdb.set_trace() try: args = json.loads(line) assert isinstance(args, dict) track_page_view(args)
# -*- coding: utf-8 -*- """ wsgi ~~~~ receiver wsgi module """ from werkzeug.serving import run_simple from werkzeug.wsgi import DispatcherMiddleware import receiver application = DispatcherMiddleware(receiver.create_app()) if __name__ == "__main__": run_simple( '0.0.0.0', 5000, application, use_reloader=True, use_debugger=True)
from receiver import create_app app = create_app()
def build_app(confs): logging.basicConfig(level=getattr(logging, confs["LogLevel"].upper())) app = receiver.create_app(confs.value) return app