找不到芹菜日志文件

时间:2018-12-22 19:41:23

标签: logging celery

我正在尝试查看log或print命令是否在我的任务中运行。

当我运行以下命令时:

  

celery -robobud.celery工作人员-f -l信息

它告诉我我的开始和完成任务,但我不知道它是否真正在其中运行了代码。

请帮助我找出我一直在阅读的“日志”文件在哪里。

from __future__ import absolute_import
import time
import json
import logging
from channels.layers import get_channel_layer
from robobud.celery import app
from .models import Program



log = logging.getLogger(__name__)

@app.task
async def pump(program_id, amount1, amount2):
    # time sleep represent some long running process
    time.sleep(3)
    # Change task status to completed
    #program = Program.objects.get(pk=program_id)
    log.debug("Running progam_name=%s", program.name, amount1, amount2)

    #program.status = "completed"
    #program.save()
    print("pumping")
    print(program_id, amount1, amount2)

    #Chatroom name
    chat_room = "program" + str(program_id)
    print(chat_room)
    channel_layer = get_channel_layer()

    #Create Dictionary
    taskResponse = {
            "action": "completed",
            "program_id": program.id,
            "program_name": program.name,
            "program_status": program.status,
        }

    # Broadcasts the message to be sent
    await channel_layer.group_send(
        chat_room,
        {
            "type": "task_message",
            "text": json.dumps(taskResponse)
        }
    )

    @database_sync_to_async #Critical when pulling data from data using async
    def set_program_status(self, program_id):
        program = Program.objects.get(id=program_id)
        program.status = "Completed"  # change field
        program.save() # this will update only

    # Send status update back to browser client
    #if program_name is not None:
    #    Channel(reply_channel).send({
    #        "text": json.dumps ({
    #            "action": "completed",
    #            "program_id": program.id,
    #            "program_name": program.name,
    #            "program_status": program.status,
    #        })
    #    })

1 个答案:

答案 0 :(得分:1)

I'm not sure how well celery与syncio一起玩,因为celery是多处理的,而asyncio是关于单个进程的,但这是一个简单的任务,它将向您展示如何对celery使用日志记录:

celery worker -A robobud.celery worker -l info

快速记下,开始芹菜的方式看起来不对。您可以使用以下语法登录到stderr:

celery -A robobud.celery worker -f /var/log/celery/%h-%I.log -l info

不过,此命令仅记录那些在info或以上记录的消息(即,不调试)。如果要将芹菜输出放入日志文件,请you can use the -f or --logfile switch to specify the location of the file,例如:

ffprobe -loglevel error -skip_frame nokey -select_streams v:0 -show_entries frame=pkt_duration_time,pkt_pos -of csv "video.mp4"