Skip to content
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

add record counting and print at the end #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions target_stitch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ def __init__(self, # pylint: disable=too-many-arguments
self.messages = []
self.buffer_size_bytes = 0
self.state = None
self.counts = {}

# Mapping from stream name to {'schema': ..., 'key_names': ..., 'bookmark_names': ... }
self.stream_meta = {}
Expand Down Expand Up @@ -438,6 +439,12 @@ def handle_line(self, line):
enough_bytes = num_bytes >= self.max_batch_bytes
enough_messages = num_messages >= self.max_batch_records
enough_time = num_seconds >= self.batch_delay_seconds

if isinstance(message, singer.RecordMessage):
if not self.counts.get(message.stream):
self.counts[message.stream] = 0
self.counts[message.stream] += 1

if enough_bytes or enough_messages or enough_time:
LOGGER.debug('Flushing %d bytes, %d messages, after %.2f seconds',
num_bytes, num_messages, num_seconds)
Expand All @@ -462,6 +469,13 @@ def consume(self, reader):
self.handle_line(line)
self.flush()

def print_counts(self):
printstr = '\n----------------------'
for stream_id, stream_count in self.counts.items():
printstr += '\n{}: {}'.format(stream_id, stream_count)
printstr += '\n----------------------'
LOGGER.info(printstr)
dmosorast marked this conversation as resolved.
Show resolved Hide resolved


def collect():
'''Send usage info to Stitch.'''
Expand Down Expand Up @@ -554,11 +568,13 @@ def main_impl():

# queue = Queue(args.max_batch_records)
reader = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
TargetStitch(handlers,
target = TargetStitch(handlers,
sys.stdout,
args.max_batch_bytes,
args.max_batch_records,
args.batch_delay_seconds).consume(reader)
args.batch_delay_seconds)
target.consume(reader)
target.print_counts()
LOGGER.info("Exiting normally")

def main():
Expand Down