Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
[HANDL-961] fix the problem that new entities are being created while…
Browse files Browse the repository at this point in the history
… syncing (#26)
  • Loading branch information
tibortezsla authored Mar 16, 2021
1 parent af21ce5 commit b7d147b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tap_twilio/sync.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import math
from datetime import timedelta, datetime
import sys
from dateutil import parser

import singer
from singer import metrics, metadata, Transformer, utils
Expand Down Expand Up @@ -412,10 +412,14 @@ def sync_endpoint(
page = page + 1
# End page/batch - while next URL loop

# Update the state with the max_bookmark_value for the stream date window
# Update the state with the sooner of now_datetime or max_bookmark_value
# If we synced any entities which were created during the synchronization process, we save the start of the
# sync as bookmark, if all we synced was entities from before we started, we save the latest entity
# Twilio API does not allow page/batch sorting; bookmark written for date window
if bookmark_field:
write_bookmark(state, stream_name, max_bookmark_value)
max_bookmark_date_time = parser.parse(max_bookmark_value)
new_bookmark_date_time = sooner_date_time(max_bookmark_date_time, now_datetime)
write_bookmark(state, stream_name, new_bookmark_date_time.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))

# Increment date window and sum endpoint_total
start_window = end_window
Expand All @@ -431,6 +435,11 @@ def sync_endpoint(
return endpoint_total


def sooner_date_time(date_time_1, date_time_2):
if date_time_1 < date_time_2:
return date_time_1
return date_time_2

# Currently syncing sets the stream currently being delivered in the state.
# If the integration is interrupted, this state property is used to identify
# the starting point to continue from.
Expand Down

0 comments on commit b7d147b

Please sign in to comment.