Add lookback duration for engagements #91
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a strange situation that can arise when records are vigorously updated while syncing the engagements stream. There are a few things that contribute to this, given the syncing strategy:
lastUpdated
, so the full data set must be inspected each run, and records emitted based on bookmark value.max_bookmark
is saved through each run and written to state after the whole dataset has been seen.The Situation
The effect of that is this potential situation:
T0: Start engagements sync
T1: Get record R1 and sync, update max_bookmark to R1[lastUpdated]
T2: Record R1 is updated
T3: Record R2 is updated
T4: Sync record R2, update max_bookmark to R2[lastUpdated]
T5: Finish engagements sync and save max_bookmark to emit records from for the next time around
In this situation, the update to record R1 that occurred at T2 is skipped on the next sync, since it's
lastUpdated
value is lower than the bookmark, saved from T2 as "max".Mitigation
In order to mitigate this, the duration of the engagements sync is stored in
STATE
underlast_sync_duration
, when present, this value will determine the amount of time (in seconds) that the bookmark should be pushed towards the past to catch any records that were updated as described above.