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.21030512.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

celery_context-0.0.3.21030512-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: celery_context-0.0.3.21030512.tar.gz
  • Upload date:
  • Size: 4.2 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.21030512.tar.gz
Algorithm Hash digest
SHA256 a2dc6d748d582dc10533dbec5962490d9a4c09c0329a9dd3988ad3a7fae00424
MD5 0f23f0f6ac8c395ff540589f282ec43f
BLAKE2b-256 9b3ab84329a821f929b4409b06378cbb51225bceec4b7af69048d5bd41f0ae9c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: celery_context-0.0.3.21030512-py3-none-any.whl
  • Upload date:
  • Size: 4.5 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.21030512-py3-none-any.whl
Algorithm Hash digest
SHA256 f371a9780f3a41be7040955117f474375aaaf17fe0400d5e14ba06f0c18830a2
MD5 b0d887cf98374a370f093513a82afa92
BLAKE2b-256 611f0f96d2ba0db8a505e3b1111e55507df62b50e50b657ae230223ca493876e

See more details on using hashes here.

Supported by

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