[
https://issues.apache.org/jira/browse/BEAM-6778?focusedWorklogId=215395&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-215395
]
ASF GitHub Bot logged work on BEAM-6778:
----------------------------------------
Author: ASF GitHub Bot
Created on: 19/Mar/19 11:45
Start Date: 19/Mar/19 11:45
Worklog Time Spent: 10m
Work Description: robertwb commented on pull request #7937: [BEAM-6778]
Enable Bundle Finalization in Python SDK harness over FnApi
URL: https://github.com/apache/beam/pull/7937#discussion_r266845550
##########
File path: sdks/python/apache_beam/runners/portability/fn_api_runner_test.py
##########
@@ -1083,6 +1131,34 @@ def __reduce__(self):
def _unpickle_element_counter(name):
return _pickled_element_counters[name]
+class EventRecorder(object):
+ """Used to be registered as a callback in bundle finalization.
+
+ The reason why records are written into a tmp file is, the in-memory dataset
+ cannot keep callback records when passing into one DoFn.
+ """
+ def __init__(self, tmp_dir):
+ self.tmp_dir = tmp_dir
+ self.file_path = os.path.join(self.tmp_dir, uuid.uuid4().hex + '.txt')
+
+ def record(self, content):
+ tmp_file = open(self.file_path, 'a')
+ tmp_file.write(content + '\n')
+ tmp_file.close()
+
+ def events(self):
+ tmp_file = open(self.file_path, 'r')
+ content = tmp_file.read()
+ tmp_file.close()
+ self.delete_file()
+ return content
Review comment:
Just a thought as to API design: it's nice to make EventRecorder encapsulate
its implementation by providing a symmetric API. For example, if I do
`record("a"); record("b"); record("c")` I would expect to get `["a", "b", "c"]`
back when asking for what was recorded, rather than a single newline-delimited
string.
----------------------------------------------------------------
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]
Issue Time Tracking
-------------------
Worklog Id: (was: 215395)
Time Spent: 6h (was: 5h 50m)
> Enable Bundle Finalization in Python SDK
> ----------------------------------------
>
> Key: BEAM-6778
> URL: https://issues.apache.org/jira/browse/BEAM-6778
> Project: Beam
> Issue Type: New Feature
> Components: sdk-py-harness
> Reporter: Boyuan Zhang
> Assignee: Boyuan Zhang
> Priority: Major
> Time Spent: 6h
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)