DRF异步执行ansible任务
今天在使用DRF做自动化部署时,使用Celery的异步功能去执行ansible任务时发现,居然一闪而过没有执行到,celery的启动命令和日志如下:
(venv) [root@localhost drf_ops]# celery -A drf_ops worker --beat -l info
[2021-09-30 09:44:57,950: WARNING/ForkPoolWorker-2] git clone code result:
[2021-09-30 09:44:57,950: WARNING/ForkPoolWorker-2]
[2021-09-30 09:44:57,950: WARNING/ForkPoolWorker-2] {'ok': {}, 'unreachable': {}, 'failed': {}, 'skipped': {}}
[2021-09-30 09:44:57,950: WARNING/ForkPoolWorker-2]
感觉有点奇怪,经过一番查询之后发现celery要加一个启动参数--pool=solo才行,马上加参数重新启动,完美运行
(venv) [root@localhost drf_ops]# celery -A drf_ops worker --beat --pool=solo -l info
[2021-09-30 09:48:35,222: WARNING/MainProcess] git clone code result:
[2021-09-30 09:48:35,223: WARNING/MainProcess]
[2021-09-30 09:48:35,223: WARNING/MainProcess] {'ok': {'localhost': {'git': {'after': '05c92f9e99aa0b7391f0c0f313a899b878f106d7', 'changed': False, 'remote_url_changed': False, 'invocation': {'module_args': {'archive_prefix': None, 'force': True, 'track_submodules': False, 'reference': None, 'umask': None, 'ssh_opts': None, 'bare': False, 'single_branch': False, 'archive': None, 'executable': None, 'recursive': True, 'verify_commit': False, 'version': 'dev', 'dest': '/srv/drf_ops/workspaces/deploy/app/开发环境/ydz-app', 'clone': True,}