Skip to content

Commit

Permalink
Retry async calls if they fail (#814)
Browse files Browse the repository at this point in the history
* Adding new event for log rocket to track when supabase calls failed
Fixing circular dep with logrocket and supabase

* More import fixes

* Adding a warning for when the network is down according to the browser
No longer clearing the cache on tables

* Updating to latest notistack
Using more custom notification styling for network

* Being safe

* Reverting the table caching display

* Making errors display with more insight for users

* Making errors display with more insight for users : new file

* Switching over to the retry library

* Getting more functions over to retrying
Cleaning up

* Fixing how a response is handled

* Comments and instruction clean up

* post merge fix

* Cleaning up typing for invoke

* clean up

* handling combined grants

* Getting connectos to retry

* Getting directives using retry

* Getting drafts using retry

* marking todo

* Getting hydration using retry

* Getting inferred schema using retry

* Do not want to throw on error to help with retry

* marking todo

* Do not want to throw on error to help with retry

* getting live specs using retry

* Getting pub view using retry

* Getting more stuff working with retry

* PR: updating name
  • Loading branch information
travjenkins authored Nov 14, 2023
1 parent a271364 commit 4a5d971
Show file tree
Hide file tree
Showing 50 changed files with 498 additions and 376 deletions.
123 changes: 71 additions & 52 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"madge": "^5.0.2",
"material-ui-popup-state": "^5.0.9",
"monaco-editor": "^0.34.1",
"notistack": "^2.0.8",
"notistack": "^3.0.1",
"p-limit": "^4.0.0",
"path-list-to-tree": "^1.1.1",
"pretty-bytes": "^6.1.0",
Expand All @@ -89,6 +89,7 @@
"react-virtualized-auto-sizer": "^1.0.20",
"react-window": "^1.8.9",
"readable-numbers": "^1.0.7",
"retry": "^0.13.1",
"safe-stable-stringify": "^2.4.3",
"serve": "^14.2.0",
"stripe": "^12.1.1",
Expand All @@ -111,6 +112,7 @@
"@types/react-gtm-module": "^2.0.1",
"@types/react-lazylog": "^4.5.1",
"@types/react-window": "^1.8.5",
"@types/retry": "^0.12.5",
"compress-create-react-app": "^1.4.1",
"eslint-config-kentcdodds": "^20.3.1",
"eslint-plugin-jest-dom": "^4.0.3",
Expand Down
14 changes: 9 additions & 5 deletions src/api/combinedGrantsExt.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { PostgrestResponse } from '@supabase/postgrest-js';
import {
defaultTableFilter,
RPCS,
SortingProps,
supabaseClient,
supabaseRetry,
TABLES,
} from 'services/supabase';
import { AuthRoles } from 'types';
Expand Down Expand Up @@ -76,11 +78,13 @@ const getGrants_Users = (
};

export const getAuthRoles = async (capability: string) => {
return supabaseClient
.rpc<AuthRoles>(RPCS.AUTH_ROLES, {
min_capability: capability,
})
.throwOnError();
return supabaseRetry<PostgrestResponse<AuthRoles>>(
() =>
supabaseClient.rpc<AuthRoles>(RPCS.AUTH_ROLES, {
min_capability: capability,
}),
'getAuthRoles'
);
};

export { getGrants, getGrants_Users };
16 changes: 10 additions & 6 deletions src/api/connectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
handleSuccess,
SortingProps,
supabaseClient,
supabaseRetry,
TABLES,
} from 'services/supabase';

Expand Down Expand Up @@ -59,12 +60,15 @@ const DETAILS_FORM_QUERY = `
`;

const getConnectors_detailsForm = async (connectorId: string) => {
const data = await supabaseClient
.from(TABLES.CONNECTORS)
.select(DETAILS_FORM_QUERY)
.eq('id', connectorId)
.eq('connector_tags.connector_id', connectorId)
.then(handleSuccess<ConnectorsQuery_DetailsForm[]>, handleFailure);
const data = await supabaseRetry(
() =>
supabaseClient
.from(TABLES.CONNECTORS)
.select(DETAILS_FORM_QUERY)
.eq('id', connectorId)
.eq('connector_tags.connector_id', connectorId),
'getConnectors_detailsForm'
).then(handleSuccess<ConnectorsQuery_DetailsForm[]>, handleFailure);

return data;
};
Expand Down
37 changes: 23 additions & 14 deletions src/api/directives.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PostgrestSingleResponse } from '@supabase/postgrest-js';
import { DIRECTIVES } from 'directives/shared';
import { UserClaims } from 'directives/types';
import {
Expand All @@ -9,6 +10,7 @@ import {
RPCS,
SortingProps,
supabaseClient,
supabaseRetry,
TABLES,
updateSupabase,
} from 'services/supabase';
Expand Down Expand Up @@ -56,12 +58,15 @@ const callUpdate = (
};

const exchangeBearerToken = async (token: string) => {
return supabaseClient
.rpc<ExchangeResponse>(RPCS.EXCHANGE_DIRECTIVES, {
bearer_token: token,
})
.throwOnError()
.single();
return supabaseRetry<PostgrestSingleResponse<ExchangeResponse>>(
() =>
supabaseClient
.rpc(RPCS.EXCHANGE_DIRECTIVES, {
bearer_token: token,
})
.single(),
'exchangeBearerToken'
);
};

const submitDirective = async (
Expand Down Expand Up @@ -146,18 +151,22 @@ const generateGrantDirective = (
};

const getDirectiveByToken = async (token: string) => {
const data = await supabaseClient
.from(TABLES.DIRECTIVES)
.select(`spec,token`)
.eq('token', token)
.then(
handleSuccess<Pick<GrantDirective, 'spec' | 'token'>[]>,
handleFailure
);
const data = await supabaseRetry(
() =>
supabaseClient
.from(TABLES.DIRECTIVES)
.select(`spec,token`)
.eq('token', token),
'getDirectiveByToken'
).then(
handleSuccess<Pick<GrantDirective, 'spec' | 'token'>[]>,
handleFailure
);

return data;
};

// Used in table hydrator which handles the retrying
const getDirectivesByType = (
directiveType: keyof typeof DIRECTIVES,
pagination: any,
Expand Down
Loading

0 comments on commit 4a5d971

Please sign in to comment.