예제 #1
0
def handle_event(message):
    """ Handles an event from the Redis Pubsub channel. If the event is one
    we care about we will spawn a new Greenlet to handle the event asynchronously.

    Argument
    --------
    event : dict
        The event data
    """

    # Create Flask Application
    app = create()

    with app.app_context():
        if message['event'] == 'play':
            add_playlist_history(message['uri'], message['user'])
예제 #2
0
    def init_app(self, app):
        """ Initialise Celery for the Flask application from the application
        configuration.

        Arguments
        ---------
        app : flask.app.Flask
            Flask application instance
        """

        from fm.app import create

        if app is None:
            app = create()

        # Create the Celery Application
        celery_app = celery.Celery(app.import_name)
        celery_app.conf.update(app.config)
        TaskBase = celery.Task

        # Custom task to ensure tasks a called with an application
        # context to allow for proper setup and teardown
        class ContextTask(TaskBase):

            abstract = True

            def __call__(self, *args, **kwargs):
                with app.app_context():
                    return TaskBase.__call__(self, *args, **kwargs)

        # If we are in always eager mode then we don't need to alter the
        # task base class
        if not celery_app.conf.get('ALWAYS_EAGER'):
            celery_app.Task = ContextTask

        # Store the celery app on on this instance for access later
        self.app = celery_app

        # Return the celery application
        return celery_app
예제 #3
0
PyTest Configuration
"""

# Standard Libs
import json

# Third Party Libs
import pytest
from flask import g
from tests.factories.user import UserFactory

# First Party Libs
from fm.app import create
from fm.ext import db as _db

_app = create()  # Create Application Instance


class Response(object):
    @property
    def json(self):
        return json.loads(self.data)


class InjectContentTypeHeader(object):
    """ All test client requests should send Content-Type: appliccation/json
    with each request. This is just for convenience.
    """
    def __init__(self, app):
        self.app = app
예제 #4
0
파일: app.py 프로젝트: thisissoon/FM-API
#!/usr/bin/env python
# encoding: utf-8
"""
fm.tasks.app
============

Celery Application Entry Point.
"""

# First Party Libs
from fm.app import create
from fm.tasks import Celery

celery = Celery(create())
예제 #5
0
#!/usr/bin/env python
# encoding: utf-8
"""
fm.wsgi
=======

WSGI App Entry Point
"""

# First Party Libs
from fm.app import create

app = create()
예제 #6
0
파일: manage.py 프로젝트: thisissoon/FM-API
=========

FM Management Command Scripts.
"""
# Third Party Libs
import alembic
from flask.ext.migrate import Migrate, MigrateCommand, _get_config
from flask.ext.script import Manager, prompt_bool

# First Party Libs
from fm import app
from fm.events.listener import listener
from fm.ext import db


app = app.create()

manager = Manager(app)
migrate = Migrate(app, db)


@manager.command
def runeventlistener():
    """ Run the Redis Event Listener. This will spawn a Gevent Greenlet.
    """

    try:
        listener()
    except KeyboardInterrupt:
        print 'Exited'