コード例 #1
0
def test_default_done_callback(app):
    executor = Executor(app)
    def callback(future):
        setattr(future, 'test', 'test')
    executor.add_default_done_callback(callback)
    with app.test_request_context('/'):
        future = executor.submit(fib, 5)
        concurrent.futures.wait([future])
        assert hasattr(future, 'test')
コード例 #2
0
            instance_path=getenv('INSTANCE_PATH'))
environment = getenv('FLASK_ENV')
if environment == 'testing' or environment == 'development':
    secret_key = environment
else:
    secret_key = getenv('SECRET_KEY') or open(getenv('SECRET_KEY_FILE')).read()
app.config.from_mapping(
    SECRET_KEY=secret_key,
    DATABASE=getenv('DATABASE'),
)

# Ensure the instance folder exists and initialize application, db and executor.
mkdir(app.instance_path)
db.init_app(app)
executor = Executor(app)
executor.add_default_done_callback(executorCallback)

#Enable CORS
if getenv('CORS') is not None:
    if getenv('CORS')[0:1] == '[':
        origins = json.loads(getenv('CORS'))
    else:
        origins = getenv('CORS')
    cors = CORS(app, origins=origins)


@executor.job
def enqueue(ticket, src_path, working_path, date, gdal_params):
    """Enqueue a transform job (in case requested response type is 'deferred')."""
    filesize = stat(src_path).st_size
    dbc = db.get_db()
コード例 #3
0
    # get job result from future
    job_res = future.result()
    app.logger.debug(job_res)
    # get and update corresponding db row object
    result = Result.query.get(job_res.get("md5"))
    result.status = job_res.get("status")
    result.report = job_res.get("stdout")
    result.error = job_res.get("stderr")

    # delete file
    os.remove(job_res.get("file_location"))
    # finally commit changes to DB
    db.session.commit()


executor.add_default_done_callback(add_result_to_db)
''' Routes '''


@app.before_first_request
def before_first_request():
    try:
        db.drop_all()
        db.create_all()
        app.logger.debug("Dropped current DB and created new instance")
    except Exception as e:
        app.logger.exception(f"Caught Exception:{e}")
        db.create_all()
        app.logger.debug("Created new DB instance")

    _upload_path = app.config.get("UPLOAD_PATH")