实现celery在flask/django下的上下文一致性的简单扩展
Project description
Documentation
The documentation is hosted at https://github.com/BingerYang/celery_context
Installation
adding the trace_id, task_name and task_id at celery log format
pip install celery_context
Usage
example:
# -*- coding: utf-8 -*- from flask import Flask from celery_context import Celery from flask import request from .. import celery_settings # 存放celery 配置的文件 """celery_settings worker_log_format = '[%(trace_id)s%(task_name)s%(task_id)s%(process)s %(thread)s %(asctime)s %(pathname)s:%(lineno)s] %(levelname)s: %(message)s' worker_task_log_format = worker_log_format """ 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, broker=redis_url, backend=redis_url) celery.config_from_object(celery_settings) celery.add_flask_content(app) @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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file celery_context-0.0.3.23092222-py2.py3-none-any.whl
.
File metadata
- Download URL: celery_context-0.0.3.23092222-py2.py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53c995055a3771956c20e1312e5c3ede8862d915e3d3cf220dc75f594443d1ac |
|
MD5 | 065f4d6a8bba20dd8a7c20d0166a7c6b |
|
BLAKE2b-256 | b0e6ae656a857a102aba340db2a89d90b51c84266f48183a943d73fc2ec33902 |