Flask-Worker simplifies interaction with a Redis Queue for executing long-running tasks in a Flask application.
Project description
Flask-Worker
Flask-Worker simplifies interaction with a Redis Queue for executing long-running tasks in a Flask application.
Long-running tasks are managed by a Worker, who sends the client a loading page until it completes the task. Upon completing the task, the Worker automatically replaces the client's window with the loaded page.
Example
Suppose a model (the employer) must run a long, complex task before the next page loads.
What we want is for the complex task to run once, and for the view function to return a loading page while the complex task is running. Additional requests to this route should not cause the complex task to run multiple times. Once the task is complete, the loaded page should appear automatically.
After setup, we can achieve this with the following:
@app.route('/')
def index():
employer = Employer.query.filter_by(name='name').first()
if employer.worker is None:
employer.worker = Worker(method_name='complex_task')
worker = employer.worker
if not worker.job_finished:
return worker()
return 'Hello World'
Documentation
You can find the latest documentation at https://dsbowen.github.io/flask-worker.
License
Publications which use this software should include the following citations for Flask-Worker and its dependency, SQLAlchemy-Mutable.
Bowen, D.S. (2019). Flask-Worker [Compluter software]. https://github.com/dsbowen/flask-worker
Bowen, D.S. (2019). SQLAlchemy-Mutable [Computer software]. https://github.com/dsbowen/sqlalchemy-mutable
This project is licensed under the MIT License LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for flask_worker-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05ee364271f1dc2eb566e13b32d6070ac8a8db2772d989845cf213f08efc3e6d |
|
MD5 | 4830cb810685d2c33597148a2b3ed500 |
|
BLAKE2b-256 | eae7155aff857b1f459b1e6968dc5c339a8286e1e90365e9d320547b7752c034 |