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

TDL-20767 resetting bookmark date to start date #178

Merged
merged 6 commits into from
May 29, 2023

Conversation

rdeshmukh15
Copy link
Contributor

@rdeshmukh15 rdeshmukh15 commented May 6, 2023

Description of change

  • Running historical sync for the respective stream when the corner case scenario(mentioned in the ticket TDL-20767) occurs

Manual QA steps

Tested following scenarios :
- Scenario 1 : subscriptions and subscription_items stream are selected, passed 15th march 2023 as created in state file for subscriptions and subscriptions_events and 1st may 2023 as created for subscription_items
==>

  1. In the first run, it should raise the exception and reset the created for subscriptions to start_date and remove subscriptions_events key from the state and same should happen with the subscription_items as well

  2. In the second run, it should fetch the historical data for subscriptions and the subscription_items stream

- Scenario 2 : If only one stream is selected and it has quite older(> 30 days) event updates then
==>

  1. In the first run, it should reset the respective stream's bookmark value to start_date and pop out the _events from the state file.
  2. Provide the final state in step 1 as an input to the 2nd run and at that time, it will run the historical run for the parent stream and data for the event updates of 30 days.

Risks

  • unit tests passing

Rollback steps

  • revert this branch

@rdeshmukh15 rdeshmukh15 force-pushed the TDL-20767-changes branch from c6aa936 to 9b3ec25 Compare May 6, 2023 05:01
if max_created != bookmark_value and (bookmark_value != start_date or flag_value is True):
reset_bookmark_for_event_updates(is_sub_stream, stream_name, sub_stream_name, start_date)
raise Exception("Provided current bookmark date for event updates is older than 30 days."\
" Hence, resetting the bookmark date of respective parent/child stream to start date.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add the name of the stream(s) to the exception message

event_update_window_size = Context.event_update_window_size
events_update_date_window_size = int(60 * 60 * 24 * event_update_window_size) # event_update_window_size in seconds
sync_start_time = dt_to_epoch(utils.now())
start_date = int(utils.strptime_to_utc(Context.config["start_date"]).timestamp())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since theres a variable for start_date now, it can be used on line 971 and 978

@@ -952,9 +952,11 @@ def sync_event_updates(stream_name, is_sub_stream):
or when called through only child stream i.e. when parent is not selected.
'''
LOGGER.info("Started syncing event based updates")
flag_value = False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this variable name be more descriptive

# Verify warning message for bookmark of less than last 30 days.
self.assertEqual(mock_logger.mock_calls, expected_logger_warning)
with self.assertRaises(Exception) as e:
sync_event_updates('charges', False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add assertions around the altered state after the exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the test where we can check he call count, not added the assertion to compare the state because reset_bookmark_for_event_updates function doesn't return anything.

@mock.patch('tap_stripe.LOGGER.warning')
def test_sync_event_updates_bookmark_before_last_7_days(self, mock_logger, mock_write_bookmark, mock_stripe_event, mock_utils_now):
@mock.patch('singer.utils.now', return_value = datetime.datetime.strptime("2023-05-10T08:30:50Z", "%Y-%m-%dT%H:%M:%SZ"))
def test_sync_event_updates_bookmark_before_last_30_days(self, mock_utils_now, mock_stripe_event):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also add a test where two streams are selected

@rdeshmukh15 rdeshmukh15 merged commit 1457c83 into master May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants