Skip to content

pallets-eco/flask-rq

Folders and files

NameName
Last commit message
Last commit date
May 22, 2024
May 22, 2024
May 21, 2024
Apr 3, 2013
May 21, 2024
Nov 12, 2012
May 21, 2024
May 21, 2024
May 21, 2024
Nov 12, 2012
Nov 12, 2012
Jul 19, 2012
May 21, 2024
May 21, 2024
May 21, 2024
May 21, 2024

Repository files navigation

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.

Resources

  • Documentation <http://packages.python.org/Flask-RQ/>_
  • Issue Tracker <http://github.com/mattupstate/flask-rq/issues>_
  • Code <http://github.com/mattupstate/flask-rq/>_
  • Development Version <http://github.com/mattupstate/flask-rq/zipball/develop#egg=Flask-RQ-dev>_

Installation

$ pip install flask-rq

Getting started

To quickly start using rq, simply create an RQ instance:

from flask import Flask
from flask.ext.rq import RQ


app = Flask(__name__)

RQ(app)

@job decorator

Provides a way to quickly set a function as an rq job:

from flask.ext.rq import job


@job
def process(i):
    #  Long stuff to process


process.delay(3)

A specific queue name can also be passed as argument:

@job('low')
def process(i):
    #  Long stuff to process


process.delay(2)

get_queue function

Returns default queue or specific queue for name given as argument:

from flask.ext.rq import get_queue


job = 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:

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:

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:

app.config['RQ_LOW_URL'] = 'redis://localhost:6379/2'