benbenbang commented on a change in pull request #5137: [AIRFLOW-4363] Add
try-catch for retrieving `status` from cli in docker operator
URL: https://github.com/apache/airflow/pull/5137#discussion_r277128057
##########
File path: airflow/operators/docker_operator.py
##########
@@ -198,9 +198,21 @@ def execute(self, context):
if self.force_pull or len(self.cli.images(name=self.image)) == 0:
self.log.info('Pulling docker image %s', self.image)
for l in self.cli.pull(self.image, stream=True):
- output = json.loads(l.decode('utf-8').strip())
- if 'status' in output:
- self.log.info("%s", output['status'])
+ try:
Review comment:
If I print them out, it looks like:
```
[2019-04-20 10:11:53,334] {docker_operator.py:188} INFO - Starting docker
container from image hello-world
[2019-04-20 10:11:53,352] {docker_operator.py:202} INFO - Pulling docker
image hello-world
[2019-04-20 10:11:55,977] {docker_operator.py:204} INFO -
b'{"status":"Pulling from library/hello-world","id":"latest"}\r\n'
[2019-04-20 10:11:55,978] {docker_operator.py:208} INFO - Pulling from
library/hello-world
[2019-04-20 10:11:56,714] {docker_operator.py:204} INFO -
b'{"status":"Pulling fs layer","progressDetail":{},"id":"1b930d010525"}\r\n'
[2019-04-20 10:11:56,715] {docker_operator.py:208} INFO - Pulling fs layer
[2019-04-20 10:11:57,816] {docker_operator.py:204} INFO -
b'{"status":"Downloading","progressDetail":{"current":501,"total":977},"progress":"[=========================\\u003e
] 501B/977B","id":"1b930d010525"}\r\n'
[2019-04-20 10:11:57,816] {docker_operator.py:208} INFO - Downloading
[2019-04-20 10:11:57,860] {docker_operator.py:204} INFO -
b'{"status":"Downloading","progressDetail":{"current":977,"total":977},"progress":"[==================================================\\u003e]
977B/977B","id":"1b930d010525"}\r\n{"status":"Verifying
Checksum","progressDetail":{},"id":"1b930d010525"}\r\n'
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services