Skip to content

Instantly share code, notes, and snippets.

@tommedema
Created March 15, 2021 20:20
Show Gist options
  • Save tommedema/0f80ae4c7334e6531c56c598643f0eb7 to your computer and use it in GitHub Desktop.
Save tommedema/0f80ae4c7334e6531c56c598643f0eb7 to your computer and use it in GitHub Desktop.
// 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