Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of celery Native configuration File in SORA

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the example analysis of celery native configuration file in SORA, which is very detailed and has certain reference value. Friends who are interested must read it!

Let's take out the configuration item of celery.py and create a celeryconfig.py in the proj directory, as follows:

CELERY_TASK_RESULT_EXPIRES=3600CELERY_TASK_SERIALIZER='json'CELERY_ACCEPT_CONTENT= ['json'] CELERY_RESULT_SERIALIZER='json'

Modify celery.py:

From _ _ future__ import absolute_importfrom celery import Celeryapp = Celery ('proj', broker='amqp://guest@localhost//', backend='amqp://guest@loaclhost//', include= [' proj.agent']) # app.conf.update (# CELERY_TASK_RESULT_EXPIRES=3600,# CELERY_TASK_SERIALIZER='json',# CELERY_ACCEPT_CONTENT= ['json']) # CELERY_RESULT_SERIALIZER='json'#) app.config_from_object ('proj.celeryconfig') if _ _ name__ = =' _ main__': app.start ()

Use app.config_from_object () to import the configuration. Note that the path:module,celeryconfig file is in the same directory as the celery file in the following format.

Start it up:

Root@workgroup0:~/celeryapp/configtest# celery-A proj worker-l info/usr/local/lib/python2.7/dist-packages/celery/platforms.py:766: RuntimeWarning: You are running the worker with superuser privileges, which isabsolutely not endeavors Please specify a different user using the-u option.User information: uid=0 euid=0 gid=0 egid=0 uid=uid, euid=euid, gid=gid, egid=egid -celery@workgroup0 v3.1.17 (Cipater)-*-- *-* *-- [config]-* * -. > app: proj:0x7fade8bc1550- * * -. > transport: amqp://guest:**@localhost:5672//- * * -. > results: amqp://guest@loaclhost//- * -. > concurrency: 1 (prefork)-- * * *-[queues] -. > celery exchange=celery (direct) key=celery [tasks]. Proj.agent.add. Proj.agent.mul [2015-04-05 16 INFO/MainProcess] mingle: searching for neighbors [2015-04-05 16 INFO/MainProcess] mingle: all alone [2015-04-05 1626 mingle: WARNING/MainProcess] celery@workgroup0 ready.Cworker: Hitting Ctrl+C again will terminate all running tasksworker: Warm shutdown (MainProcess)

It started successfully.

The experience of hitting a brick wall on the way: because at the beginning, I copied the configuration content of celery.py directly without removing the comma between the configuration contents, like this:

CELERY_TASK_RESULT_EXPIRES=3600,CELERY_TASK_SERIALIZER='json',CELERY_ACCEPT_CONTENT= ['json'], CELERY_RESULT_SERIALIZER='json'

Causes worker to fail to start. Later, I looked at the example of the official document and solved the problem. Just get rid of those commas.

Reflection: although celery can also use this form of configuration:

From celery import Celeryapp = Celery () class Config: CELERY_ENABLE_UTC = True CELERY_TIMEZONE = 'Europe/London'app.config_from_object (Config) # or using the fully qualified name of the object:# app.config_from_object (' module:Config')

You can also configure it using app.config_from_envvar (), but I think it's more convenient the way I use it. And put the configuration contents in a separate file to avoid modifying the source code.

SORA may use app.conf.update to cooperate with configparser to configure worker, on the one hand, it can avoid users' direct contact with celery configuration, and at the same time, it can unify the configuration mode of the whole project (refer to various conf files of openstack).

The above is all the contents of the article "sample Analysis of celery Native configuration Files in SORA". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report