实现celery在flask下的上下文一致性的简单扩展
Project description
Documentation
The documentation is hosted at https://github.com/BingerYang/flask_celery_context
Installation
pip install flask_celery_context
Usage
example:
# -*- coding: utf-8 -*-
from flask import Flask
from flask_celery import Celery
from flask import request
config = dict(redis={"host": "*****", "port": 31320, "password": "lab@2019"})
redis_url = "redis://:{password}@{host}:{port}".format(**config["redis"])
app = Flask("example.run")
app.config['CELERY_BROKER_URL'] = "{}/1".format(redis_url)
app.config['CELERY_RESULT_BACKEND'] = "{}/2".format(redis_url)
celery = Celery(app)
celery.setup_task_context(lambda: dict(path=request.path))
@celery.task(bind=True)
def add(self, a, b):
print("a+ n:", a + b, self.request.content)
return a + b
@app.route("/")
def index():
ret = add.delay(1, 3)
print(ret.get())
return ret.id
if __name__ == "__main__":
app.run()
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_celery_context-0.0.1.20040717.tar.gz.
File metadata
- Download URL: flask_celery_context-0.0.1.20040717.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
451809a70d058c14418abe8f8faa1dcf3f03f6f4ced94e79546133e3bfb553ac
|
|
| MD5 |
0b37cca44b50b6f2896272569c8b3b8f
|
|
| BLAKE2b-256 |
569dd195dad29eca462ee83e88bceb03f0fb9ed88d5601a234ede9dc6d2f62ff
|
File details
Details for the file flask_celery_context-0.0.1.20040717-py3-none-any.whl.
File metadata
- Download URL: flask_celery_context-0.0.1.20040717-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.6.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7200670e54c68314cb6ad8b59d89b0586630dc709ef2a9dc1c6f3035eb2dac99
|
|
| MD5 |
41423da88b4813f0ebdd941f095bdf0a
|
|
| BLAKE2b-256 |
34c248700f360ecad0fe3bcca54627ef85fb7ca4c4de592f862cb4b4b0d31cf9
|