【发布时间】:2014-04-22 06:16:02
【问题描述】:
我创建了 celery 任务来运行一些通过 nodejs 用 javascript 编写的各种作业。该任务基本上是一个调用nodejs的subprocess.popen。
nodejs 作业在退出时将返回非零状态,以及写入 stderr 的错误信息。
发生这种情况时,我想获取标准错误,并将这些作为“结果”返回给 celery,以及 FAILURE 状态,这样我的作业监视器可以反映作业失败。
我该怎么做?
这是我的任务
@app.task
def badcommand():
try:
output = subprocess.check_output('ls foobar',stderr=subprocess.STDOUT,shell=True)
return output
except subprocess.CalledProcessError as er:
#What do I do here to return er.output, and set the status to fail?
如果我没有捕捉到子进程异常,作业会正常失败,但结果是空的,我会得到一个回溯堆栈跟踪。
如果我捕捉到异常,并返回er.output,则作业成功完成。
【问题讨论】: