Skip to content

Commit

Permalink
feat: [FFM-6509]: Clear metrics after 2 failed attempts (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
knagurski authored Jan 18, 2023
1 parent a907c38 commit ac6688f
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 34 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,21 @@ In case you want to import this library directly (without having to use npm or y

```html
<script type="module">
import { initialize, Event } from 'https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.5.0/dist/sdk.client.js'
import { initialize, Event } from 'https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.6.0/dist/sdk.client.js'
</script>
```

If you need to support old browsers which don't support ES Module:

```html
<script src="https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.5.0/dist/sdk.client.js"></script>
<script src="https://unpkg.com/@harnessio/ff-javascript-client-sdk@1.6.0/dist/sdk.client.js"></script>
<script>
var initialize = HarnessFFSDK.initialize
var Event = HarnessFFSDK.Event
</script>
```

Remember to change the version `1.5.0` in the unpkg url accordingly.
Remember to change the version `1.6.0` in the unpkg url accordingly.

## License

Expand Down
12 changes: 6 additions & 6 deletions dist/sdk.cjs.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/sdk.client-iife.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/sdk.client.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/sdk.esm.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion examples/preact/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/react-redux/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@harnessio/ff-javascript-client-sdk",
"version": "1.5.0",
"version": "1.6.0",
"author": "Harness",
"license": "Apache-2.0",
"main": "dist/sdk.cjs.js",
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type {
import { Event } from './types'
import { defaultOptions, logError, MIN_EVENTS_SYNC_INTERVAL } from './utils'

const SDK_VERSION = '1.5.0'
const SDK_VERSION = '1.6.0'
const METRICS_VALID_COUNT_INTERVAL = 500
const fetch = globalThis.fetch
const EventSource = EventSourcePolyfill
Expand Down Expand Up @@ -109,6 +109,8 @@ const initialize = (apiKey: string, target: Target, options?: Options): Result =
return data.authToken
}

let failedMetricsCallCount = 0

const scheduleSendingMetrics = () => {
if (metrics.length) {
logDebug('Sending metrics...', { metrics, evaluations })
Expand Down Expand Up @@ -161,8 +163,13 @@ const initialize = (apiKey: string, target: Target, options?: Options): Result =
})
.then(() => {
metrics = []
failedMetricsCallCount = 0
})
.catch(error => {
if (failedMetricsCallCount++) {
metrics = []
failedMetricsCallCount = 0
}
logDebug(error)
})
.finally(() => {
Expand Down

0 comments on commit ac6688f

Please sign in to comment.