实现celery在flask/django下的上下文一致性的简单扩展
Project description
Documentation
The documentation is hosted at https://github.com/BingerYang/celery_context
Installation
pip install celery_context
Usage
example:
# -*- coding: utf-8 -*- from flask import Flask from celery_context 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=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
Close
Hashes for celery_context-0.0.2.20052710.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9b020a0393dd0c4b6f09a1f0c1226499222f33f2dfee0aee0a758350c880191 |
|
MD5 | e51842f6fa4070366354c34e777fb073 |
|
BLAKE2b-256 | a14be24ce8a5c707487616ba0bdb30f0af269cb43bc636b347bb41763d8a8385 |
Close
Hashes for celery_context-0.0.2.20052710-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7dfc0c62d384e32b8f610b33b96b4307f7eedee0e2e29cf8c0d15d62fac396f |
|
MD5 | 14a88211e59c852008139287a7310b26 |
|
BLAKE2b-256 | cd6fa9828b941bfda908d0877c77ff8ad2212b9cf3bfe478a420022af0c78839 |