예제 #1
0
    def main(testmode=False, workdir=lib_folder):
        if MynedataBackendCtl.backend_process is not None:
            return
        if not Configuration.initialized:
            Configuration.initialize()

        mynedata_backend_command = 'celery worker {tasks} {workdir} {celerybeat} {testmode} {logfile} {loglevel} {autoscale}'.format(
            tasks='-A lib.backend.tasks.app -B',
            workdir='--workdir {}'.format(workdir),
            celerybeat='--schedule=/tmp/celerybeat-schedule',
            testmode='--testmode' if testmode else '',
            logfile='--logfile=/opt/mynedata/log/backend.log',
            loglevel='--loglevel=debug',
            autoscale='--autoscale %s,%s' %
            (Configuration.concurrency_max, Configuration.concurrency_min),
        )

        if testmode:
            Configuration.enable_test_mode()
        Configuration.print_config()

        MynedataBackendCtl.backend_process = subprocess.Popen(
            mynedata_backend_command, shell=True)
        with open(PID_FILE, 'w') as f_pid:
            f_pid.write(str(MynedataBackendCtl.backend_process.pid) + '\n')
예제 #2
0
파일: app.py 프로젝트: COMSYS/mynedata
    def __init__(self, worker, test_mode, **options):
        Configuration.initialize()
        if test_mode:
            Configuration.enable_test_mode()
        Configuration.print_config()
        worker.app.config_from_object(Configuration)
        DatabaseConnector.initialize(target=Configuration.database_uri)

        # Initialize payments
        if Configuration.payment_mode in [
                PaymentMethod.BITCOIN_DIRECT,
                PaymentMethod.BITCOIN_QUERY_BASED,
                PaymentMethod.BITCOIN_CENTRAL
        ]:
            BitcoinConnector.initialize()
예제 #3
0
파일: endpoint.py 프로젝트: COMSYS/mynedata
def make_celery(flaskapp, test_mode=False):
    """ Launch Celery. """
    cel = celery.Celery(flaskapp.import_name)
    cel.conf.update(flaskapp.config)
    if test_mode:
        Configuration.enable_test_mode()
    cel.config_from_object(Configuration)
    taskbase = cel.Task

    class ContextTask(taskbase):
        """ Create a flask context task. """
        abstract = True

        def __call__(self, *args, **kwargs):
            with flaskapp.app_context():
                return taskbase.__call__(self, *args, **kwargs)

    cel.Task = ContextTask
    return cel