实现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.21030314.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd8eb857e7c98d92abdf98b87b7106f33e1809a207440b7b85c30fc9c2b206b6 |
|
MD5 | ebcabf44d5079aa61ccaf903b7098197 |
|
BLAKE2b-256 | b9a0df9a5fe4fdac95b603ef49fbfd67b6f1d697f45134d8a495e66a8ff4420c |
Close
Hashes for celery_context-0.0.2.21030314-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00cc3955a6ca81866cdff5814c9e4ef82bf6ddf3f89b130106dfbfa497b59b71 |
|
MD5 | 6b258908761c05f3a75e1512d75371c8 |
|
BLAKE2b-256 | 9eb6e1b3cda26e8082b648a660ac410b27bc2cbf9120fad2cea62d02e119f578 |