-
-
Save tommedema/0f80ae4c7334e6531c56c598643f0eb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Attempt to flush to amplitude | |
// Retryable failed events are sent to a retry queue | |
// Otherwise an application error is logged | |
try { | |
await flushAmplitude() | |
} catch (e) { | |
if (!(e instanceof AmplitudeFlushError)) { | |
throw e | |
} | |
for (const failedEventDescription of e.failedEventDescriptions) { | |
const { isRetryable, event: amplitudeEvent, retryInMs } = failedEventDescription | |
// Note that while an event is retryable, it may still have been processed by Amplitude | |
// This is because Amplitude only returns a single status per batch | |
// Fortunately, there is no risk of event duplication here because Amplitude | |
// Performs a deduplication based on each Amplitude event's `insert_id` | |
if (isRetryable) { | |
// TODO: send to retry queue here | |
console.log('Retry amplitudeEvent %o in %s ms', amplitudeEvent, retryInMs) | |
} else { | |
console.error('Error - flush error for event: ' + JSON.stringify(failedEventDescription)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment