Esempio n. 1
0
def init_app(app):
    admin = Admin(app,
                  name=app.config.get('APP_NAME', __pkg_name__),
                  index_view=AdminRoleIndexView(menu_icon_type='fa', menu_icon_value='fa-home'),
                  base_template='admin_master.html',
                  template_mode='bootstrap3',
                  category_icon_classes={
                      'Models': 'fa fa-database',
                      'Tools': 'fa fa-briefcase',
                      'Home': 'fa fa-home'
                  })
    # Add model views
    admin.add_view(RoleView(Role, db.session, name='Roles', endpoint='roles', category='Models',
                            menu_icon_type='fa', menu_icon_value='fa-user-plus'))
    admin.add_view(UserView(User, db.session, name='Users', endpoint='users', category='Models',
                            menu_icon_type='fa', menu_icon_value='fa-users'))
    # Add Redis console for Celery broker
    backend, url = get_backend_by_url(app.config.get('BROKER_URL'))
    if backend is RedisBackend:
        admin.add_view(SuperuserRedisCliView(Redis.from_url(url), name='Redis CLI', endpoint='rediscli',
                                             category='Tools'))

    security_ctx = app.extensions['security']

    @security_ctx.context_processor
    def security_context_processor():  # pylint: disable=unused-variable
        return dict(
            admin_base_template=admin.base_template,
            admin_view=admin.index_view,
            h=admin_helpers,
            get_url=admin_helpers.get_url
        )
Esempio n. 2
0
 def test_backend_by_url(self, url='riak://myhost/mycoolbucket'):
     """
     test get backend by url
     """
     from celery import backends
     from celery.backends.riak import RiakBackend
     backend, url_ = backends.get_backend_by_url(url, self.app.loader)
     self.assertIs(backend, RiakBackend)
     self.assertEqual(url_, url)
Esempio n. 3
0
 def test_backend_by_url(self, url='riak://myhost/mycoolbucket'):
     """
     test get backend by url
     """
     from celery import backends
     from celery.backends.riak import RiakBackend
     backend, url_ = backends.get_backend_by_url(url, self.app.loader)
     self.assertIs(backend, RiakBackend)
     self.assertEqual(url_, url)
Esempio n. 4
0
    def test_get_backend_aliases(self):
        expects = [('amqp://', AMQPBackend), ('cache+memory://', CacheBackend)]

        for url, expect_cls in expects:
            backend, url = backends.get_backend_by_url(url, self.app.loader)
            self.assertIsInstance(
                backend(app=self.app, url=url),
                expect_cls,
            )
Esempio n. 5
0
    def test_get_backend_aliases(self):
        expects = [('amqp://', AMQPBackend),
                   ('cache+memory://', CacheBackend)]

        for url, expect_cls in expects:
            backend, url = backends.get_backend_by_url(url, self.app.loader)
            self.assertIsInstance(
                backend(app=self.app, url=url),
                expect_cls,
            )
Esempio n. 6
0
def init_app(app):
    admin = Admin(app,
                  name=app.config.get('APP_NAME', __pkg_name__),
                  index_view=AdminRoleIndexView(menu_icon_type='fa',
                                                menu_icon_value='fa-home'),
                  base_template='admin_master.html',
                  template_mode='bootstrap3',
                  category_icon_classes={
                      'Models': 'fa fa-database',
                      'Tools': 'fa fa-briefcase',
                      'Home': 'fa fa-home'
                  })
    # Add model views
    admin.add_view(
        RoleView(Role,
                 db.session,
                 name='Roles',
                 endpoint='roles',
                 category='Models',
                 menu_icon_type='fa',
                 menu_icon_value='fa-user-plus'))
    admin.add_view(
        UserView(User,
                 db.session,
                 name='Users',
                 endpoint='users',
                 category='Models',
                 menu_icon_type='fa',
                 menu_icon_value='fa-users'))
    # Add Redis console for Celery broker
    backend, url = get_backend_by_url(app.config.get('BROKER_URL'))
    if backend is RedisBackend:
        admin.add_view(
            SuperuserRedisCliView(Redis.from_url(url),
                                  name='Redis CLI',
                                  endpoint='rediscli',
                                  category='Tools'))

    security_ctx = app.extensions['security']

    @security_ctx.context_processor
    def security_context_processor():  # pylint: disable=unused-variable
        return dict(
            admin_base_template=admin.base_template,
            admin_view=admin.index_view,
            h=admin_helpers,
        )
Esempio n. 7
0
def get_cache(app):
    """
    Attempt to find a valid cache from the Celery configuration

    If the setting is a valid cache, just use it.
    Otherwise, if Django is installed, then:
        If the setting is a valid Django cache entry, then use that.
        If the setting is empty use the default cache
    Otherwise, if Werkzeug is installed, then:
        If the setting is a valid Celery Memcache or Redis Backend, then use
            that.
        If the setting is empty and the default Celery Result Backend is
            Memcache or Redis, then use that
    Otherwise fail
    """
    jobtastic_cache_setting = app.conf.get('JOBTASTIC_CACHE')
    if isinstance(jobtastic_cache_setting, BaseCache):
        return jobtastic_cache_setting

    if 'Django' in CACHES:
        if jobtastic_cache_setting:
            try:
                return WrappedCache(get_django_cache(jobtastic_cache_setting))
            except InvalidCacheBackendError:
                pass
        else:
            return WrappedCache(get_django_cache('default'))

    if 'Werkzeug' in CACHES:
        if jobtastic_cache_setting:
            backend, url = get_backend_by_url(jobtastic_cache_setting)
            backend = backend(app=app, url=url)
        else:
            backend = app.backend

        if isinstance(backend, CacheBackend):
            return WrappedCache(MemcachedCache(backend.client))
        elif isinstance(backend, RedisBackend):
            return WrappedCache(RedisCache(backend.client))

    # Give up
    raise RuntimeError('Cannot find a suitable cache for Jobtastic')
Esempio n. 8
0
def get_cache(app):
    """
    Attempt to find a valid cache from the Celery configuration

    If the setting is a valid cache, just use it.
    Otherwise, if Django is installed, then:
        If the setting is a valid Django cache entry, then use that.
        If the setting is empty use the default cache
    Otherwise, if Werkzeug is installed, then:
        If the setting is a valid Celery Memcache or Redis Backend, then use
            that.
        If the setting is empty and the default Celery Result Backend is
            Memcache or Redis, then use that
    Otherwise fail
    """
    jobtastic_cache_setting = app.conf.get("JOBTASTIC_CACHE")
    if isinstance(jobtastic_cache_setting, BaseCache):
        return jobtastic_cache_setting

    if "Django" in CACHES:
        if jobtastic_cache_setting:
            try:
                return WrappedCache(get_django_cache(jobtastic_cache_setting))
            except InvalidCacheBackendError:
                pass
        else:
            return WrappedCache(get_django_cache("default"))

    if "Werkzeug" in CACHES:
        if jobtastic_cache_setting:
            backend, url = get_backend_by_url(jobtastic_cache_setting)
            backend = backend(app=app, url=url)
        else:
            backend = app.backend

        if isinstance(backend, CacheBackend):
            return WrappedCache(MemcachedCache(backend.client))
        elif isinstance(backend, RedisBackend):
            return WrappedCache(RedisCache(backend.client))

    # Give up
    raise RuntimeError("Cannot find a suitable cache for Jobtastic")
Esempio n. 9
0
 def test_backend_by_url(self, app, url='redis://localhost/1'):
     from celery.backends.redis import RedisBackend
     backend, url_ = backends.get_backend_by_url(url, app.loader)
     assert backend is RedisBackend
     assert url_ == url
Esempio n. 10
0
 def test_get_backend_aliases(self, url, expect_cls, app):
     backend, url = backends.get_backend_by_url(url, app.loader)
     assert isinstance(backend(app=app, url=url), expect_cls)
Esempio n. 11
0
 def test_backend_by_url(self, url='couchbase://myhost/mycoolbucket'):
     from celery.backends.couchbase import CouchBaseBackend
     backend, url_ = backends.get_backend_by_url(url, self.app.loader)
     self.assertIs(backend, CouchBaseBackend)
     self.assertEqual(url_, url)
Esempio n. 12
0
 def test_backend_by_url(self, url='couchdb://myhost/mycoolcontainer'):
     from celery.backends.couchdb import CouchBackend
     backend, url_ = backends.get_backend_by_url(url, self.app.loader)
     assert backend is CouchBackend
     assert url_ == url
Esempio n. 13
0
    def test_backend_by_url(self, url='elasticsearch://localhost:9200/index'):
        backend, url_ = backends.get_backend_by_url(url, self.app.loader)

        self.assertIs(backend, ElasticsearchBackend)
        self.assertEqual(url_, url)
Esempio n. 14
0
 def test_backend_by_url(self, url='couchdb://myhost/mycoolcontainer'):
     from celery.backends.couchdb import CouchBackend
     backend, url_ = backends.get_backend_by_url(url, self.app.loader)
     self.assertIs(backend, CouchBackend)
     self.assertEqual(url_, url)
Esempio n. 15
0
 def _get_backend(self):
     from celery.backends import get_backend_by_url
     backend, url = get_backend_by_url(
         self.backend_cls or self.conf.CELERY_RESULT_BACKEND, self.loader)
     return backend(app=self, url=url)
Esempio n. 16
0
 def _get_backend(self):
     from celery.backends import get_backend_by_url
     backend, url = get_backend_by_url(
         self.backend_cls or self.conf.result_backend, self.loader)
     return backend(app=self, url=url)
Esempio n. 17
0
 def test_backend_by_url(self, url='couchbase://myhost/mycoolbucket'):
     from celery.backends.couchbase import CouchBaseBackend
     backend, url_ = backends.get_backend_by_url(url, self.app.loader)
     self.assertIs(backend, CouchBaseBackend)
     self.assertEqual(url_, url)
Esempio n. 18
0
 def test_backend_by_url(self, url='riak://myhost/mycoolbucket'):
     from celery import backends
     from celery.backends.riak import RiakBackend
     backend, url_ = backends.get_backend_by_url(url, self.app.loader)
     assert backend is RiakBackend
     assert url_ == url
Esempio n. 19
0
 def test_backend_by_url(self, url='riak://myhost/mycoolbucket'):
     from celery import backends
     from celery.backends.riak import RiakBackend
     backend, url_ = backends.get_backend_by_url(url, self.app.loader)
     assert backend is RiakBackend
     assert url_ == url
Esempio n. 20
0
    def test_backend_by_url(self, url='elasticsearch://localhost:9200/index'):
        backend, url_ = backends.get_backend_by_url(url, self.app.loader)

        assert backend is ElasticsearchBackend
        assert url_ == url
Esempio n. 21
0
 def test_backend_by_url(self, url='couchbase://myhost/mycoolbucket'):
     from celery.backends.couchbase import CouchbaseBackend
     backend, url_ = backends.get_backend_by_url(url, self.app.loader)
     assert backend is CouchbaseBackend
     assert url_ == url
Esempio n. 22
0
    def test_backend_by_url(self, url='elasticsearch://localhost:9200/index'):
        backend, url_ = backends.get_backend_by_url(url, self.app.loader)

        self.assertIs(backend, ElasticsearchBackend)
        self.assertEqual(url_, url)
Esempio n. 23
0
 def test_backend_by_url(self, url="redis://localhost/1"):
     from celery.backends.redis import RedisBackend
     backend, url_ = backends.get_backend_by_url(url)
     self.assertIs(backend, RedisBackend)
     self.assertEqual(url_, url)
Esempio n. 24
0
    def test_backend_by_url(self, app, url="redis://localhost/1"):
        from celery.backends.redis import RedisBackend

        backend, url_ = backends.get_backend_by_url(url, app.loader)
        assert backend is RedisBackend
        assert url_ == url
Esempio n. 25
0
 def _get_backend(self):
     from celery.backends import get_backend_by_url
     backend, url = get_backend_by_url(
         self.backend_cls or self.conf.result_backend,
         self.loader)
     return backend(app=self, url=url)
Esempio n. 26
0
    def test_backend_by_url(self, url='elasticsearch://localhost:9200/index'):
        backend, url_ = backends.get_backend_by_url(url, self.app.loader)

        assert backend is ElasticsearchBackend
        assert url_ == url
Esempio n. 27
0
 def _get_backend(self):
     from celery.backends import get_backend_by_url
     backend, url = get_backend_by_url(
         self.backend_cls or self.conf.CELERY_RESULT_BACKEND,
         self.loader)
     return backend(app=self, url=url)
Esempio n. 28
0
 def test_get_backend_aliases(self, url, expect_cls, app):
     backend, url = backends.get_backend_by_url(url, app.loader)
     assert isinstance(backend(app=app, url=url), expect_cls)
Esempio n. 29
0
 def test_backend_by_url(self, url='couchbase://myhost/mycoolbucket'):
     from celery.backends.couchbase import CouchbaseBackend
     backend, url_ = backends.get_backend_by_url(url, self.app.loader)
     assert backend is CouchbaseBackend
     assert url_ == url
Esempio n. 30
0
 def test_backend_by_url(self, url='couchdb://myhost/mycoolcontainer'):
     from celery.backends.couchdb import CouchBackend
     backend, url_ = backends.get_backend_by_url(url, self.app.loader)
     assert backend is CouchBackend
     assert url_ == url