Per line bash logging
This commit is contained in:
Родитель
df8b4b0629
Коммит
46f927faab
|
@ -1,5 +1,5 @@
|
|||
import logging
|
||||
from subprocess import Popen, PIPE
|
||||
from subprocess import Popen, STDOUT, PIPE
|
||||
|
||||
from airflow.models import BaseOperator
|
||||
from airflow.utils import apply_defaults
|
||||
|
@ -25,12 +25,13 @@ class BashOperator(BaseOperator):
|
|||
|
||||
logging.info("Runnning command: " + bash_command)
|
||||
sp = Popen(
|
||||
bash_command, shell=True, stdout=PIPE, stderr=PIPE)
|
||||
out, err = sp.communicate()
|
||||
sp.wait()
|
||||
bash_command, shell=True, stdout=PIPE, stderr=STDOUT)
|
||||
|
||||
logging.info("Output:")
|
||||
for line in iter(sp.stdout.readline, ''):
|
||||
logging.info(line.strip())
|
||||
sp.wait()
|
||||
logging.info("Command exited with return code %d", sp.returncode)
|
||||
|
||||
logging.info("Command STDOUT:\n" + out)
|
||||
if err:
|
||||
logging.error(err)
|
||||
if sp.returncode:
|
||||
raise Exception("Bash command failed")
|
||||
|
|
Загрузка…
Ссылка в новой задаче