-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Fix returning last log line in docker operator #13793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,7 +219,7 @@ def get_hook(self) -> DockerHook: | |
| tls=self.__get_tls_config(), | ||
| ) | ||
|
|
||
| def _run_image(self) -> Optional[str]: | ||
| def _run_image(self) -> Optional[bytes]: | ||
| """Run a Docker container with the provided image""" | ||
| self.log.info('Starting docker container from image %s', self.image) | ||
|
|
||
|
|
@@ -269,14 +269,17 @@ def _run_image(self) -> Optional[str]: | |
| # duplicated conditional logic because of expensive operation | ||
| ret = None | ||
| if self.do_xcom_push: | ||
| ret = self.cli.logs(container=self.container['Id']) if self.xcom_all else line.encode('utf-8') | ||
| if self.xcom_all: | ||
| ret = self.cli.logs(container=self.container['Id']) | ||
| else: | ||
| ret = self.cli.logs(container=self.container['Id'], tail=1).strip() | ||
|
|
||
| if self.auto_remove: | ||
| self.cli.remove_container(self.container['Id']) | ||
|
|
||
| return ret | ||
|
|
||
| def execute(self, context) -> Optional[str]: | ||
| def execute(self, context) -> Optional[bytes]: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we perhaps decode utf-8 (assuming that's what comes out of logs, so that we return a string type? sincere question... 🤔
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. coincidence someone is doing exactly that: https://github.com/apache/airflow/pull/13536/files
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, and I think this would make more sense, but again I wanted to avoid a breaking change... I would actually be happy with this other PR being merged, as it now includes the fix in my PR. |
||
| self.cli = self._get_cli() | ||
| if not self.cli: | ||
| raise Exception("The 'cli' should be initialized before!") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not strip here also?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it should probably be stripped, but my intention was to keep the current behavior when
do_xcom_pushandxcom_allare all true.