Skip to main content

实现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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

celery_context-0.0.3.21030419.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

celery_context-0.0.3.21030419-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file celery_context-0.0.3.21030419.tar.gz.

File metadata

  • Download URL: celery_context-0.0.3.21030419.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.7.7

File hashes

Hashes for celery_context-0.0.3.21030419.tar.gz
Algorithm Hash digest
SHA256 984c7238f33816581b9d031d89ab3eb50a9456d7690a60aca73a06f98fa339e5
MD5 6013d4ecba1a1bc4202b96731cf0d6e6
BLAKE2b-256 1169a85d7e8403ae295837ff4728c5df4bc3df451be46ba0c8123ed330c21926

See more details on using hashes here.

File details

Details for the file celery_context-0.0.3.21030419-py3-none-any.whl.

File metadata

  • Download URL: celery_context-0.0.3.21030419-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.7.7

File hashes

Hashes for celery_context-0.0.3.21030419-py3-none-any.whl
Algorithm Hash digest
SHA256 ff14c1e1caf199dd395bf4c519d6e31348411d9a90b8de152c87b80141e3c43f
MD5 5605b4a3f4f22e65c12fd04c6e678e18
BLAKE2b-256 d54d1c405f4d45fa2c556147b813d7d997dda25cc135d27657b9147bff8d0cf6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page