Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pallets-eco/flask-rq
RQ (Redis Queue) integration for Flask applications
https://github.com/pallets-eco/flask-rq
Last synced: 8 days ago
JSON representation
RQ (Redis Queue) integration for Flask applications
- Host: GitHub
- URL: https://github.com/pallets-eco/flask-rq
- Owner: pallets-eco
- License: mit
- Created: 2012-07-17T05:19:01.000Z (over 12 years ago)
- Default Branch: main
- Last Pushed: 2024-05-22T16:05:16.000Z (6 months ago)
- Last Synced: 2024-05-22T16:54:53.077Z (6 months ago)
- Language: Python
- Size: 48.8 KB
- Stars: 211
- Watchers: 8
- Forks: 32
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
- awesome-flask - Flask-RQ - [RQ](https://python-rq.org/) (Redis Queue) integration. (Third-Party Extensions / Task Queues)
- jimsghstars - pallets-eco/flask-rq - RQ (Redis Queue) integration for Flask applications (Python)
README
# Flask-RQ
RQ (Redis Queue) integration for Flask applications
## Pallets Community Ecosystem
> [!IMPORTANT]\
> This project is part of the Pallets Community Ecosystem. Pallets is the open
> source organization that maintains Flask; Pallets-Eco enables community
> maintenance of related projects. If you are interested in helping maintain
> this project, please reach out on [the Pallets Discord server][discord].[discord]: https://discord.gg/pallets
## Resources
- `Documentation `_
- `Issue Tracker `_
- `Code `_
- `Development Version
`_## Installation
```bash
$ pip install flask-rq
```## Getting started
To quickly start using `rq`, simply create an RQ instance:
```python
from flask import Flask
from flask.ext.rq import RQapp = Flask(__name__)
RQ(app)
```### ``@job`` decorator
Provides a way to quickly set a function as an ``rq`` job:
```python
from flask.ext.rq import job@job
def process(i):
# Long stuff to processprocess.delay(3)
```A specific queue name can also be passed as argument:
```python
@job('low')
def process(i):
# Long stuff to processprocess.delay(2)
```### ``get_queue`` function
Returns default queue or specific queue for name given as argument:
```python
from flask.ext.rq import get_queuejob = get_queue().enqueue(stuff) # Creates a job on ``default`` queue
job = get_queue('low').enqueue(stuff) # Creates a job on ``low`` queue
```### ``get_worker`` function
Returns a worker for default queue or specific queues for names given as arguments:
```python
from flask.ext.rq import get_worker# Creates a worker that handle jobs in ``default`` queue.
get_worker().work(True)
# Creates a worker that handle jobs in both ``default`` and ``low`` queues.
get_worker('default', 'low').work(True)
# Note: These queues have to share the same connection
```## Configuration
By default Flask-RQ will connect to the default, locally running
Redis server. One can change the connection settings for the default
server like so:```python
app.config['RQ_DEFAULT_HOST'] = 'somewhere.com'
app.config['RQ_DEFAULT_PORT'] = 6479
app.config['RQ_DEFAULT_PASSWORD'] = 'password'
app.config['RQ_DEFAULT_DB'] = 1
```Queue connection can also be set using a DSN:
```python
app.config['RQ_LOW_URL'] = 'redis://localhost:6379/2'
```