现在我正在使用芹菜来处理我的部署脚本(结构)。所以我需要将每个项目部署日志保存到数据库,然后我可以检查部署是否完美运行。但是我仍然没有找到保存每个任务日志的正确方法,并且对使用芹菜记录器有点困惑。 我正在使用芹菜2.5.1
views.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)
tasks.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
fabfile.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'])
答案 0 :(得分:-1)
class LogEntry(models.Model):
timestamp = models.DateTimeField(auto_now_add=True)
severity = models.CharField(blank=False, max_length=10)
message = models.TextField(blank=False)
@task
def deploy(deploy_settings):
log = LogEntry(severity="INFO", message="Deploying....")
log.save()
fabfile.deploy_settings = deploy_settings
fabfile.run_all() #run the deployment script, I need to save all the output message
return True