芹菜任务记录器不写

时间:2012-06-18 15:45:22

标签: python logging celery

我对芹菜的记录器有问题。我有一个渲染帧的功能。我记录了我生成的子进程的输出,但似乎只写了每个worker写入队列的第一个作业。队列中的所有后续任务都不会生成日志文件。我也尝试过使用python自己的日志记录,同样的问题也会发生。有没有可能缺少的配置?

 @task(queue='rndr')
 def rndr(params):

     path      = get_logger_path(params)
     logger    = rndr.get_logger(logfile=path)    
     return render(params, logger)

我以这种方式定义我的任务,因为我的重试记录器的定义不同,即rndr_retry.get_logger ...

我的celeryconfig如下所示:

 BROKER_HOST = "xxx.xxx.xxx.xxx"
 BROKER_PORT = 5672
 BROKER_USER = "xxxx"
 BROKER_PASSWORD = "xxxx"

 CELERY_RESULT_BACKEND = 'amqp'
 CELERY_DISABLE_RATE_LIMITS = True
 CELERY_ACKS_LATE = True
 CELERY_IMPORTS = ['lib.tasks.concatenate', 'lib.tasks.encode', 'lib.tasks.render',  'lib.tasks.still_image', 'lib.tasks.retry']
 CELERY_ROUTES = {'lib.tasks.encode':{'queue': 'encode'},
             'lib.tasks.concatenate':{'queue': 'encode'},
             'lib.tasks.still_image':{'queue': 'encode'},
             'lib.tasks.render':{'queue':'rndr'},
             'lib.tasks.retry':{'queue': 'retry'}
             }

希望有人能够解释为什么只有队列中的第一个任务写出来......

提前谢谢。

更新:这里要求的是渲染方法的部分版本,没有所有细节......

def render(params, logger):

    #load params to local values

    try:
        #create subprocess
        output = child_proc.communicate()[0]

        logger.info('output')
        logger.info(output)       
        ret = child_proc.wait()                
        if ret not in [0,1]:
            raise Exception('subprocess failed')              

    except Exception, exc:
        logger.info(' '.join(str(x) for x in exc.args))
        #mark as failed...
        return          

    return

我应该补充说,不仅在后续任务中不会写入文件,它甚至不会创建日志文件....

1 个答案:

答案 0 :(得分:3)

经过一些试验,我注意到没有创建传递的日志文件。我添加了一个方法来确保文件存在,然后将其传递给get_logger()。仍然没有运气。由于我的大多数任务都运行subprocess,我决定采用一种更简单的方法并拥有一个打开的文件对象,并将其传递给stdout和stderr中的子进程调用,并在适当的位置关闭文件对象。无论我运行多少任务,这似乎都有效。我应该注意每个任务写入一个唯一的文件。

Anyhoo,我想我会写信给celery devs并将其标记为bug。我曾经在某个地方的开发论坛上看过,芹菜的记录器需要一些爱。

干杯。

更新

与芹菜开发者交谈后得出的结论是,记录器并不是以这种方式使用的。为任务启动日志记录实例,但重复的任务不会记录。我最终只是写一个文件来规避Logging模块的问题。诀窍并不会导致任何冲突,因为每个渲染任务都使用唯一的文件。

相关问题