国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

django celery 記錄

這篇具有很好參考價值的文章主要介紹了django celery 記錄。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

django celery 記錄

dvadmin-celery

Django+Django-Celery+Celery的整合實戰(zhàn)

https://cloud.tencent.com/developer/article/1445252

https://blog.csdn.net/wowocpp/article/details/131475484

https://docs.celeryq.dev/en/latest/django/first-steps-with-django.html

https://docs.celeryq.dev/en/latest/django/index.html

http://docs.celeryproject.org/en/latest/

https://github.com/pylixm/celery-examples

https://pylixm.cc/posts/2015-12-03-Django-celery.html
中文
https://www.celerycn.io/ru-men/celery-chu-ci-shi-yong

中文
https://docs.jinkan.org/docs/celery/

Python Django構(gòu)建簡易CMDB
https://blog.51cto.com/u_15352934/3819825

簡約而不簡單的 Django 新手圖文教程
https://zhuanlan.zhihu.com/p/393724439

牛哄哄的celery
https://www.cnblogs.com/pyedu/p/12461819.html

example

https://github.com/celery/celery

django celery 記錄,django,python,后端

Backends and Brokers
Brokers 消息中間件 消息轉(zhuǎn)發(fā)

django celery 記錄,django,python,后端
django celery 記錄,django,python,后端
Celery的架構(gòu)由三部分組成,消息中間件(message broker),任務執(zhí)行單元(worker)和任務執(zhí)行結(jié)果存儲(task result store)組成。

消息中間件

Celery本身不提供消息服務,但是可以方便的和第三方提供的消息中間件集成。包括,RabbitMQ, Redis等等

任務執(zhí)行單元

Worker是Celery提供的任務執(zhí)行的單元,worker并發(fā)的運行在分布式的系統(tǒng)節(jié)點中。

任務結(jié)果存儲

Task result store用來存儲Worker執(zhí)行的任務的結(jié)果,Celery支持以不同方式存儲任務的結(jié)果,包括AMQP, redis等

另外, Celery還支持不同的并發(fā)和序列化的手段

并發(fā):Prefork, Eventlet, gevent, threads/single threaded
序列化:pickle, json, yaml, msgpack. zlib, bzip2 compression, Cryptographic message signing 等等

第一個例子:

python3 -m venv demo1_venv
source demo1_venv/bin/activate
mkdir work
cd work/
pip install -U Celery
pip install redis
mkdir CeleryTask
vi celery_task.py


import celery
import time
backend='redis://127.0.0.1:6379/1'
broker='redis://127.0.0.1:6379/2'
cel=celery.Celery('test',backend=backend,broker=broker)
@cel.task
def send_email(name):
    print("向%s發(fā)送郵件..."%name)
    time.sleep(5)
    print("向%s發(fā)送郵件完成"%name)
    return "ok"

django celery 記錄,django,python,后端

celery -A celery_task worker -l info

(demo1_venv) mike@ubuntu:~/work/CeleryTask$ celery  -A celery_task worker -l info
 
 -------------- celery@ubuntu v5.3.1 (emerald-rush)
--- ***** ----- 
-- ******* ---- Linux-5.15.0-76-generic-x86_64-with-glibc2.29 2023-07-03 02:40:28
- *** --- * --- 
- ** ---------- [config]
- ** ---------- .> app:         test:0x7f985fa979a0
- ** ---------- .> transport:   redis://127.0.0.1:6379/2
- ** ---------- .> results:     redis://127.0.0.1:6379/1
- *** --- * --- .> concurrency: 1 (prefork)
-- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
--- ***** ----- 
 -------------- [queues]
                .> celery           exchange=celery(direct) key=celery
                

[tasks]
  . celery_task.send_email

[2023-07-03 02:40:28,783: WARNING/MainProcess] /home/mike/demo1_venv/lib/python3.8/site-packages/celery/worker/consumer/consumer.py:498: CPendingDeprecationWarning: The broker_connection_retry configuration setting will no longer determine
whether broker connection retries are made during startup in Celery 6.0 and above.
If you wish to retain the existing behavior for retrying connections on startup,
you should set broker_connection_retry_on_startup to True.
  warnings.warn(

[2023-07-03 02:40:28,806: INFO/MainProcess] Connected to redis://127.0.0.1:6379/2
[2023-07-03 02:40:28,808: WARNING/MainProcess] /home/mike/demo1_venv/lib/python3.8/site-packages/celery/worker/consumer/consumer.py:498: CPendingDeprecationWarning: The broker_connection_retry configuration setting will no longer determine
whether broker connection retries are made during startup in Celery 6.0 and above.
If you wish to retain the existing behavior for retrying connections on startup,
you should set broker_connection_retry_on_startup to True.
  warnings.warn(

[2023-07-03 02:40:28,811: INFO/MainProcess] mingle: searching for neighbors
[2023-07-03 02:40:29,827: INFO/MainProcess] mingle: all alone
[2023-07-03 02:40:29,870: INFO/MainProcess] celery@ubuntu ready.

django celery 記錄,django,python,后端

第二個例子

mkdir app
vi tasks.py


from celery import Celery
backend='redis://127.0.0.1:6379/3'
broker='redis://127.0.0.1:6379/4'
app = Celery('tasks', broker=broker, backend=backend)
@app.task
def add(x, y):
        return x + y

啟動實例任務celery worker (消費者)

celery -A tasks worker --loglevel=info
等待 redis中 來消息之后,執(zhí)行任務
django celery 記錄,django,python,后端

調(diào)用實例任務 (生產(chǎn)者)

給 消息隊列發(fā)送消息(redis)
django celery 記錄,django,python,后端

可以
celery worker --help

Usage: celery worker [OPTIONS]

  Start worker instance.

  Examples
  --------

  $ celery --app=proj worker -l INFO
  $ celery -A proj worker -l INFO -Q hipri,lopri
  $ celery -A proj worker --concurrency=4
  $ celery -A proj worker --concurrency=1000 -P eventlet
  $ celery worker --autoscale=10,0

Worker Options:
  -n, --hostname HOSTNAME         Set custom hostname (e.g., 'w1@%%h').
                                  Expands: %%h (hostname), %%n (name) and %%d,
                                  (domain).
  -D, --detach                    Start worker as a background process.
  -S, --statedb PATH              Path to the state database. The extension
                                  '.db' may be appended to the filename.
  -l, --loglevel [DEBUG|INFO|WARNING|ERROR|CRITICAL|FATAL]
                                  Logging level.
  -O, --optimization [default|fair]
                                  Apply optimization profile.
  --prefetch-multiplier <prefetch multiplier>
                                  Set custom prefetch multiplier value for
                                  this worker instance.

Pool Options:
  -c, --concurrency <concurrency>
                                  Number of child processes processing the
                                  queue.  The default is the number of CPUs
                                  available on your system.
  -P, --pool [prefork|eventlet|gevent|solo|processes|threads|custom]
                                  Pool implementation.
  -E, --task-events, --events     Send task-related events that can be
                                  captured by monitors like celery events,
                                  celerymon, and others.
  --time-limit FLOAT              Enables a hard time limit (in seconds
                                  int/float) for tasks.
  --soft-time-limit FLOAT         Enables a soft time limit (in seconds
                                  int/float) for tasks.
  --max-tasks-per-child INTEGER   Maximum number of tasks a pool worker can
                                  execute before it's terminated and replaced
                                  by a new worker.
  --max-memory-per-child INTEGER  Maximum amount of resident memory, in KiB,
                                  that may be consumed by a child process
                                  before it will be replaced by a new one.  If
                                  a single task causes a child process to
                                  exceed this limit, the task will be
                                  completed and the child process will be
                                  replaced afterwards. Default: no limit.

Queue Options:
  --purge, --discard
  -Q, --queues COMMA SEPARATED LIST
  -X, --exclude-queues COMMA SEPARATED LIST
  -I, --include COMMA SEPARATED LIST

Features:
  --without-gossip
  --without-mingle
  --without-heartbeat
  --heartbeat-interval INTEGER
  --autoscale <MIN WORKERS>, <MAX WORKERS>

Embedded Beat Options:
  -B, --beat
  -s, --schedule-filename, --schedule TEXT
  --scheduler TEXT

Daemonization Options:
  -f, --logfile TEXT  Log destination; defaults to stderr
  --pidfile TEXT
  --uid TEXT
  --gid TEXT
  --umask TEXT
  --executable TEXT

Options:
  --help  Show this message and exit.

celery --help

Usage: celery [OPTIONS] COMMAND [ARGS]...

  Celery command entrypoint.

Options:
  -A, --app APPLICATION
  -b, --broker TEXT
  --result-backend TEXT
  --loader TEXT
  --config TEXT
  --workdir PATH
  -C, --no-color
  -q, --quiet
  --version
  --skip-checks          Skip Django core checks on startup.
  --help                 Show this message and exit.

Commands:
  amqp     AMQP Administration Shell.
  beat     Start the beat periodic task scheduler.
  call     Call a task by name.
  control  Workers remote control.
  events   Event-stream utilities.
  graph    The ``celery graph`` command.
  inspect  Inspect the worker at runtime.
  list     Get info from broker.
  logtool  The ``celery logtool`` command.
  migrate  Migrate tasks from one broker to another.
  multi    Start multiple worker instances.
  purge    Erase all messages from all known task queues.
  report   Shows information useful to include in bug-reports.
  result   Print the return value for a given task id.
  shell    Start shell session with convenient access to celery symbols.
  status   Show list of workers that are online.
  upgrade  Perform upgrade between versions.
  worker   Start worker instance.

backend 任務結(jié)果后端

Celery 進階使用

https://www.celerycn.io/ru-men/celery-jin-jie-shi-yong

在 work目錄下創(chuàng)建proj目錄
django celery 記錄,django,python,后端
celery.py

from __future__ import absolute_import, unicode_literals
from celery import Celery

backend='redis://127.0.0.1:6379/5'
broker='redis://127.0.0.1:6379/6'


app = Celery('proj',
             broker=broker,
             backend=backend,
             include=['proj.tasks'])

# Optional configuration, see the application user guide.
app.conf.update(
    result_expires=3600,
)

if __name__ == '__main__':
    print("hello")
    app.start()

vi tasks.py


from __future__ import absolute_import, unicode_literals
from .celery import app

@app.task
def add(x, y):
    return x + y

@app.task
def mul(x, y):
    return x * y

@app.task
def xsum(numbers):
    return sum(numbers)

測試的話
在work目錄下面執(zhí)行
celery -A proj worker -l info

django celery 記錄,django,python,后端
work目錄下面執(zhí)行:文章來源地址http://www.zghlxwxcb.cn/news/detail-519385.html

python3
>>> from proj.tasks import add
>>> add.delay(2,2)
<AsyncResult: 32a194e0-1e91-49bf-8436-b215beb96e16>

到了這里,關(guān)于django celery 記錄的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務器費用

相關(guān)文章

  • Django+celery開啟時報錯

    django.db.utils.DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias \\\'default\\\' was created in thread id 19767205568 00 and this is thread id 1976775359680. 問題: 執(zhí)行celery worker -A s1 -l info -P eventlet能正常,放立即執(zhí)行的任務(delay)沒有問題,不過放apply_async的任務

    2024年02月11日
    瀏覽(14)
  • redis(其它操作、管道)、django中使用redis(通用方案、 第三方模塊)、django緩存、celery介紹(celery的快速使用)

    redis(其它操作、管道)、django中使用redis(通用方案、 第三方模塊)、django緩存、celery介紹(celery的快速使用)

    1 redis其它操作 2 redis管道 3 django中使用redis 3.1 通用方案 3.2 第三方模塊 4 django緩存 5 celery介紹 5.1 celery的快速使用

    2024年02月07日
    瀏覽(26)
  • Django高級擴展之celery使用

    Django高級擴展之celery使用

    Celery是一個簡單、靈活、可靠的分布式系統(tǒng),用于處理大量消息,同時為操作提供維護此類系統(tǒng)所需的工具。是一個專注于實時處理的任務隊列,同時還支持任務調(diào)度。 目錄 應用場景 問題 解決 celery架構(gòu)圖 安裝 配置celery Settings.py配置 創(chuàng)建celery 修改__init__ 開啟celery 異步執(zhí)行

    2024年02月11日
    瀏覽(22)
  • django celery period 周期 例子

    django celery period 周期 例子 Django 借助 Celery 實現(xiàn)計劃任務排期及調(diào)度系統(tǒng)(django-celery-beat) good https://www.jianshu.com/p/f22346379dbe https://django-celery-results.readthedocs.io/en/latest/ https://django-celery-beat.readthedocs.io/en/latest/ 五、運行測試 為了使系統(tǒng)正常運行,需要同時開啟三個服務: web 服

    2024年02月12日
    瀏覽(16)
  • Django(21):使用Celery任務框架

    Django(21):使用Celery任務框架

    Django Web項目中我們經(jīng)常需要執(zhí)行耗時的任務比如發(fā)送郵件、調(diào)用第三方接口、批量處理文件等等,將這些任務異步化放在后臺運行可以有效縮短請求響應時間。另外服務器上經(jīng)常會有定時任務的需求,比如清除緩存、備份數(shù)據(jù)庫等工作。Celery是一個高效的異步任務隊列/基于

    2024年02月07日
    瀏覽(27)
  • 利用Django和Celery管理定時任務

    同步發(fā)表于個人站點: http://panzhixiang.cn/article/2023/3/16/68.html 我們以前一直使用k8s的cronjob來管理定時任務的。把定時任務相關(guān)的代碼單獨封裝成一個pod,然后以cronjob的方法來觸發(fā)。 雖然這個方法操作很簡單,沒有什么第三方資源的依賴(比如Redis),但是也有一個明顯的缺點

    2024年02月07日
    瀏覽(21)
  • django中使用celery和接口緩存

    celery中要使用djagno的東西,才要加這句話 ? ? ?? ?import os? ? ? ? ? ? ? ? ? ? ? ? ? os.environ.setdefault(\\\"DJANGO_SETTINGS_MODULE\\\", \\\"luffy_api.settings.dev\\\") 加載django的配置文件,,將app加入到環(huán)境變量中 當一個接口是去數(shù)據(jù)庫取東西,返回給前端,比如圖片,等,每個人訪問都要去數(shù)

    2024年02月12日
    瀏覽(30)
  • Django高級擴展之系統(tǒng)后臺使用celery

    Django高級擴展之系統(tǒng)后臺使用celery

    如果我們在系統(tǒng)后臺想某日某時執(zhí)行某個任務,或者每隔一段時間執(zhí)行某個任務,可以使用celery來完成。 目錄 安裝 安裝celery 安裝django_celery_beat celery配置 注冊應用 celery配置 修改__init__.py 表遷移 執(zhí)行遷移 控制臺運行截圖 新增數(shù)據(jù)表 安裝django-celery-results 執(zhí)行命令 注冊應用

    2024年02月11日
    瀏覽(26)
  • Django+Celery框架自動化定時任務開發(fā)

    Django+Celery框架自動化定時任務開發(fā)

    本章介紹使用DjCelery即Django+Celery框架開發(fā)定時任務功能,在Autotestplat平臺上實現(xiàn)單一接口自動化測試腳本、業(yè)務場景接口自動化測試腳本、App自動化測試腳本、Web自動化測試腳本等任務的定時執(zhí)行、調(diào)度、管理等,從而取代Jenkins上的定時執(zhí)行腳本和發(fā)送郵件等功能。** 自動化

    2024年04月15日
    瀏覽(30)
  • Django 如何使用 Celery 完成異步任務或定時任務

    以前版本的 Celery 需要一個單獨的庫(django-celery)才能與 Django 一起工作, 但從 Celery 3.1 開始,情況便不再如此,我們可以直接通過 Celery 庫來完成在 Django 中的任務。 以 Docker 安裝為例,安裝一個密碼為 mypassword 的 Redis 服務端 在 Django 項目中創(chuàng)建一個 celery.py 文件,并配置

    2023年04月25日
    瀏覽(17)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包