def init_celery(app=None):
    """ Setup celery with application factory """
    if app is None:
        from project.server import create_app
        app = create_app()
    celery.conf.update(app.config)
    celery.conf.broker_url = app.config["CELERY_BROKER_URL"]
    celery.conf.result_backend = app.config["CELERY_RESULT_BACKEND"]
    celery.conf.broker_connection_max_retries = 3
    celery.conf.broker_transport_options = {
        "max_retries": 3,
        "interval_start": 0,
        "interval_step": 0.2,
        "interval_max": 0.5
    }
    celery.conf.task_publish_retry_policy = {
        "max_retries": 3,
        "interval_start": 0,
        "interval_step": 0.2,
        "interval_max": 0.5
    }

    class ContextTask(celery.Task):
        """Make celery tasks work with Flask app context"""
        def __call__(self, *args, **kwargs):
            with app.app_context():
                return self.run(*args, **kwargs)

    celery.Task = ContextTask
    return celery
Example #2
0
def app():
    """An application for the tests."""
    _app = create_app("tests.settings")
    ctx = _app.test_request_context()
    ctx.push()

    yield _app

    ctx.pop()
Example #3
0
def app():
    """Create application for the tests."""
    _app = create_app("project.server.config.TestingConfig")
    _app.logger.setLevel(logging.CRITICAL)
    ctx = _app.test_request_context()
    ctx.push()

    yield _app

    ctx.pop()
Example #4
0
# manage.py
import unittest
from time import sleep

import coverage

from flask.cli import FlaskGroup

from project.server import create_app, db
from project.server.models import User
from project.server.pickle_builder import DataScienceModelsPersistor
import sys

app = create_app()
cli = FlaskGroup(create_app=create_app)

# code coverage
COV = coverage.coverage(
    branch=True,
    include="project/*",
    omit=[
        "project/tests/*",
        "project/server/config__.py",
        "project/server/*/__init__.py",
    ],
)
#COV.start()


@cli.command()
def create_db():
Example #5
0
 def create_app(self):
     app_settings = os.getenv('APP_SETTINGS',
                              'project.server.config.ProductionConfig')
     app = create_app(app_settings)
     return app
Example #6
0
 def create_app(self):
     app_settings = os.getenv('APP_SETTINGS',
                              'project.server.config.DevelopmentConfig')
     app = create_app(app_settings)
     return app
Example #7
0
import os
import coverage
import unittest

from flask_migrate import Migrate, MigrateCommand
from project.server import create_app, db
from dotenv import load_dotenv

dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
if os.path.exists(dotenv_path):
    load_dotenv(dotenv_path)

app_settings = os.getenv('APP_SETTINGS',
                         'project.server.config.DevelopmentConfig')
app = create_app(app_settings)

migrate = Migrate(app, db)

COV = coverage.coverage(branch=True,
                        include='project/*',
                        omit=[
                            'project/tests/*', 'project/server/config.py',
                            'project/server/*/__init__.py'
                        ])
COV.start()


@app.cli.command()
def test():
    """Run tests under without coverage."""
    tests = unittest.TestLoader().discover('project/tests', pattern='test*.py')
Example #8
0
# project/server/main/works.py

import time
from rq import get_current_job
from project.server import create_app

app = create_app()
app.app_context().push()


def _set_task_progress(task):
    """
    This method will update the job progress using the task object
    :param task : Task
    :return:
    """
    job = get_current_job()
    if job:
        job.meta['progress'] = task.export()
        job.save_meta()


def long_work(tsk):
    """
    This method will start uploading the images provided by the tsk object
    :param tsk:
    :return:
    """
    tsk.executeAll(_set_task_progress)
Example #9
0
def test_app():
    app = create_app()
    app.config.from_object("project.server.config.TestingConfig")
    with app.app_context():
        yield app  # testing happens here