0

Right now I'm using celery to handle my deployment script(fabric). So I need to save every project deployment log to database, then later I can check whether the deployment run perfectly or not. However I still haven't found the right way to save each task log and a little bit confused about using the celery logger. I'm using celery 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'])
Agus
  • 73
  • 4

1 Answers1

-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
catherine
  • 22,492
  • 12
  • 61
  • 85
  • okay thanks for the code. But if I use that code, I can only save the message field to "Deploying...." isn't it? I want save all celery output from the fabric task (eg. cloning from git, creating db, etc) – Agus Mar 06 '13 at 08:34
  • Can I ask you how you implement that deploy(deploy_settings) in the views? can you post your codes – catherine Mar 06 '13 at 08:40