现在我正在使用 celery 来处理我的部署脚本(织物)。所以我需要将每个项目部署日志保存到数据库中,然后我可以检查部署是否完美运行。但是我仍然没有找到保存每个任务日志的正确方法,并且对使用 celery 记录器有点困惑。我正在使用芹菜 2.5.1
视图.py
def deploy(request, project_slug):
project = get_object_or_404(Project, slug=project_slug)
deploy_settings = simplejson.loads(project.result) #settings in json format
tasks.deploy.delay(deploy_settings)
任务.py
from celery.task import task
from deployer import fabfile
@task
def deploy(deploy_settings):
logger = deploy.get_logger()
fabfile.deploy_settings = deploy_settings
fabfile.clone() #run the deployment script, I need to save all the output message
return True
工厂文件.py
env.host_string = 'example@example.com'
env.password = 'example'
deploy_settings = {}
def clone():
with cd(deploy_settings['PATH_TO_APPS']):
run('mkdir %s' % deploy_settings['PROJECT_SLUG'])
run('git clone %s %s' % (deploy_settings['URL'], deploy_settings['PROJECT_SLUG']))
with cd('%s/example/' % deploy_settings['PROJECT_SLUG']):
run('git checkout %s' % deploy_settings['BRANCH'])