6
Python Celery 任务执行有时成功有时失败(提示NotRegistered)
source link: https://blog.51cto.com/u_2371418/5166076
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Python Celery 任务执行有时成功有时失败(提示NotRegistered)
原创环境:Centos 7.4 + Python3 + Flask + Redis
问题场景:同一任务,同样参数,任务创建后有时执行成功,有时执行失败
失败的错误如下:
Celery 配置信息如下:
if os.getenv('REDIS_PASSWORD'):CELERY_BROKER_URL = 'redis://:{}@redis:6379/2' . format(os.getenv('REDIS_PASSWORD'))
CELERY_RESULT_BACKEND = 'redis://:{}@redis:6379/2'.format(os.getenv('REDIS_PASSWORD'))
else:
CELERY_BROKER_URL = 'redis://redis:6379/2'
CELERY_RESULT_BACKEND = 'redis://redis:6379/2'
CELERYD_CONCURRENCY = 1 #并发worker数量
CELERY_TIMEZONE = 'Asia/Shanghai' #时区
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERYD_FORCE_EXECV = True #防止死锁,应确保为True
CELERYD_PREFETCH_MULTIPLIER = 1 #禁用任务预取
CELERYD_MAX_TASKS_PER_CHILD = 100 #worker执行100个任务自动销毁,防止内存泄露
CELERYD_TASK_SOFT_TIME_LIMIT = 6000 #单个任务的运行时间不超过此值(秒),否则会抛出(SoftTimeLimitExceeded)异常停止任务。
CELERY_DISABLE_RATE_LIMITS = True #即使任务设置了明确的速率限制,也禁用所有速率限制。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK