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

Break out of infinite loop and bookmark on date window end #46

Merged
merged 3 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
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
17 changes: 8 additions & 9 deletions tap_zendesk/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,13 @@ def sync(self, state):
# need to check total response size before iterating
# See: https://develop.zendesk.com/hc/en-us/articles/360022563994--BREAKING-New-Search-API-Result-Limits
if users.count > 1000:
search_window_size = search_window_size // 2
end = start + datetime.timedelta(seconds=search_window_size)
LOGGER.info("users - Detected Search API response size too large. Cutting search window in half to %s seconds.", search_window_size)
continue
if search_window_size > 1:
search_window_size = search_window_size // 2
end = start + datetime.timedelta(seconds=search_window_size)
LOGGER.info("users - Detected Search API response size too large. Cutting search window in half to %s seconds.", search_window_size)
continue

raise Exception("users - Unable to get all users within minimum window of a single second ({}), found {} users within this timestamp. Zendesk can only provide a maximum of 1000 users per request. See: https://develop.zendesk.com/hc/en-us/articles/360022563994--BREAKING-New-Search-API-Result-Limits".format(parsed_start, users.count))
cosimon marked this conversation as resolved.
Show resolved Hide resolved

# Consume the records to account for dates lower than window start
users = [user for user in users] # pylint: disable=unnecessary-comprehension
Expand All @@ -203,13 +206,9 @@ def sync(self, state):
# If we make it here, all quality checks have passed. Reset retry count.
num_retries = 0
cosimon marked this conversation as resolved.
Show resolved Hide resolved
for user in users:
if bookmark < utils.strptime_with_tz(user.updated_at) <= end:
# NB: We don't trust that the records come back ordered by
# updated_at (we've observed out-of-order records),
# so we can't save state until we've seen all records
self.update_bookmark(state, user.updated_at)
if parsed_start <= user.updated_at <= parsed_end:
yield (self.stream, user)
self.update_bookmark(state, parsed_end)

# Assumes that the for loop got everything
singer.write_state(state)
Expand Down
4 changes: 3 additions & 1 deletion test/test_bookmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def do_test(self, conn_id):
if r['data']['id'] == self.created_user.id]
self.assertTrue(any(new_record))
# NB: GreaterEqual because we suspect Zendesk updates users in the backend
self.assertGreaterEqual(len(messages), 2, msg="Sync'd incorrect count of messages: {}".format(len(messages)))
# >= 1 because we're no longer inclusive of the last replicated user record. The lookback will control this going forward.
# If we get the user we wanted and then some, this assertion should succeed
self.assertGreaterEqual(len(messages), 1, msg="Sync'd incorrect count of messages: {}".format(len(messages)))


messages = records.get('satisfaction_ratings', {}).get('messages', [])
Expand Down