Skip to main content

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.

Why Flask-Worker

Suppose we have a view function which needs to execute a complex task before the client can view the page. 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. Our first pass might be:

@app.route('/')
def index():
    return complex_task()

Unfortunately, the view function executes the complex task every time it is called. To make matters worse, the client has no indication that the complex task is in progress. Each time the client tries to refresh the page, the complex task is queued up again.

Flask-Worker solves this problem. We set up a Worker:

class Worker(WorkerMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)

    def __init__(self, name):
        self.name = name
        self.set(complex_task)
        super().__init__()

And call it in a view function:

@app.route('/')
def index():
    worker = get_model(Worker, name='index')
    return worker.result if worker.job_finished else worker()

See the tutorial for a complete example.

Installation

$ pip install flask-worker

Citation

@software{bowen2020flask-worker,
  author = {Dillon Bowen},
  title = {Flask-Worker},
  url = {https://dsbowen.github.io/flask-worker/},
  date = {2020-06-15},
}

License

Users must cite this package in any publications which use it.

It is licensed with the MIT License.

Metadata

Release files for flask-worker 0.0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-worker 0.0.14
File Size Uploaded
flask-worker-0.0.14.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flask-worker 0.0.14
File Interpreter ABI Platform
flask_worker-0.0.14-py3-none-any.whl Python 3 none any Details

Total release size: 21.4 kB

Release files / flask-worker-0.0.14.tar.gz

Download URL flask-worker-0.0.14.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f44250fd721aa2886fd57775cd26649aab23ff910308873128a762e1e821fb6a
BLAKE2b-256 checksum
How to use checksums
5620d65c6bd69e6cc169077b8fd66a7cc26df3ca4b4de6b713f09f67597ffb44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.8

Release files / flask_worker-0.0.14-py3-none-any.whl

Download URL flask_worker-0.0.14-py3-none-any.whl
Size 13.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d83ede525d0fa5521df33fd05e00b68a87264226fe7c9ee0f30178caba4bc5f
BLAKE2b-256 checksum
How to use checksums
75afc1118fb26d37784b8d061e734bf3003ca7a13b17ddcd7764f7ec423b0829
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.8

Release history Release notifications | RSS feed

This release

0.0.14 This release

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

1 release file

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page