Skip to content

Commit

Permalink
Merge pull request #1677 from ral-facilities/configurable-retries
Browse files Browse the repository at this point in the history
Allow query retry setting to be configurable
  • Loading branch information
louise-davies authored Oct 2, 2024
2 parents 2633dcd + 03de9cb commit 309c2a7
Show file tree
Hide file tree
Showing 34 changed files with 502 additions and 45 deletions.
3 changes: 2 additions & 1 deletion packages/datagateway-common/src/api/cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
useMutation,
UseMutationResult,
} from 'react-query';
import retryICATErrors from './retryICATErrors';
import { useRetryICATErrors } from './retryICATErrors';

export const fetchDownloadCart = (config: {
facilityName: string;
Expand Down Expand Up @@ -57,6 +57,7 @@ export const useCart = (): UseQueryResult<DownloadCartItem[], AxiosError> => {
const facilityName = useSelector(
(state: StateType) => state.dgcommon.facilityName
);
const retryICATErrors = useRetryICATErrors();
return useQuery(
'cart',
() =>
Expand Down
7 changes: 6 additions & 1 deletion packages/datagateway-common/src/api/dataPublications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { useSelector } from 'react-redux';
import { useLocation } from 'react-router-dom';
import { getApiParams, parseSearchToQuery } from '.';
import { StateType } from '..';
import retryICATErrors from './retryICATErrors';
import { useRetryICATErrors } from './retryICATErrors';

const fetchDataPublications = (
apiUrl: string,
Expand Down Expand Up @@ -61,6 +61,7 @@ export const useDataPublicationsPaginated = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters, sort, page, results } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useQuery<
DataPublication[],
Expand Down Expand Up @@ -118,6 +119,7 @@ export const useDataPublicationsInfinite = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters, sort } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useInfiniteQuery(
[
Expand Down Expand Up @@ -154,6 +156,7 @@ export const useDataPublication = (
>
): UseQueryResult<DataPublication, AxiosError> => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const retryICATErrors = useRetryICATErrors();

return useQuery(
['dataPublication', dataPublicationId],
Expand Down Expand Up @@ -203,6 +206,7 @@ export const useDataPublications = (
additionalFilters: AdditionalFilters
): UseQueryResult<DataPublication[], AxiosError> => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const retryICATErrors = useRetryICATErrors();

return useQuery<
DataPublication[],
Expand Down Expand Up @@ -259,6 +263,7 @@ export const useDataPublicationCount = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useQuery<
number,
Expand Down
6 changes: 5 additions & 1 deletion packages/datagateway-common/src/api/datafiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {
UseQueryOptions,
} from 'react-query';
import { useQuery, useInfiniteQuery } from 'react-query';
import retryICATErrors from './retryICATErrors';
import { useRetryICATErrors } from './retryICATErrors';

export const fetchDatafiles = (
apiUrl: string,
Expand Down Expand Up @@ -62,6 +62,7 @@ export const useDatafilesPaginated = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters, sort, page, results } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useQuery<
Datafile[],
Expand Down Expand Up @@ -114,6 +115,7 @@ export const useDatafilesInfinite = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters, sort } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useInfiniteQuery(
['datafile', { sort: JSON.stringify(sort), filters }, additionalFilters], // need to stringify sort as property order is important!
Expand Down Expand Up @@ -167,6 +169,7 @@ export const useDatafileCount = (
const location = useLocation();

const filters = parseSearchToQuery(location.search).filters;
const retryICATErrors = useRetryICATErrors();

return useQuery<
number,
Expand Down Expand Up @@ -223,6 +226,7 @@ export const useDatafileDetails = (
>
): UseQueryResult<Datafile, AxiosError> => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const retryICATErrors = useRetryICATErrors();

return useQuery<
Datafile,
Expand Down
7 changes: 6 additions & 1 deletion packages/datagateway-common/src/api/datasets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
useInfiniteQuery,
UseInfiniteQueryResult,
} from 'react-query';
import retryICATErrors from './retryICATErrors';
import { useRetryICATErrors } from './retryICATErrors';

export const fetchDatasets = (
apiUrl: string,
Expand Down Expand Up @@ -60,6 +60,7 @@ export const useDataset = (
additionalFilters?: AdditionalFilters
): UseQueryResult<Dataset[], AxiosError> => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const retryICATErrors = useRetryICATErrors();

return useQuery<
Dataset[],
Expand Down Expand Up @@ -95,6 +96,7 @@ export const useDatasetsPaginated = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters, sort, page, results } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useQuery<
Dataset[],
Expand Down Expand Up @@ -147,6 +149,7 @@ export const useDatasetsInfinite = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters, sort } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useInfiniteQuery(
['dataset', { sort: JSON.stringify(sort), filters }, additionalFilters], // need to stringify sort as property order is important!
Expand Down Expand Up @@ -199,6 +202,7 @@ export const useDatasetCount = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const filters = parseSearchToQuery(location.search).filters;
const retryICATErrors = useRetryICATErrors();

return useQuery<
number,
Expand Down Expand Up @@ -242,6 +246,7 @@ export const useDatasetDetails = (
datasetId: number
): UseQueryResult<Dataset, AxiosError> => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const retryICATErrors = useRetryICATErrors();

return useQuery<Dataset, AxiosError, Dataset, [string, number]>(
['datasetDetails', datasetId],
Expand Down
6 changes: 5 additions & 1 deletion packages/datagateway-common/src/api/facilityCycles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
useInfiniteQuery,
UseInfiniteQueryResult,
} from 'react-query';
import retryICATErrors from './retryICATErrors';
import { useRetryICATErrors } from './retryICATErrors';

const fetchFacilityCycles = (
apiUrl: string,
Expand Down Expand Up @@ -79,6 +79,7 @@ export const useAllFacilityCycles = (
enabled?: boolean
): UseQueryResult<FacilityCycle[], AxiosError> => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const retryICATErrors = useRetryICATErrors();

return useQuery<FacilityCycle[], AxiosError, FacilityCycle[], string>(
'facilityCycle',
Expand All @@ -100,6 +101,7 @@ export const useFacilityCyclesPaginated = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters, sort, page, results } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useQuery<
FacilityCycle[],
Expand Down Expand Up @@ -157,6 +159,7 @@ export const useFacilityCyclesInfinite = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters, sort } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useInfiniteQuery(
['facilityCycle', instrumentId, { sort: JSON.stringify(sort), filters }],
Expand Down Expand Up @@ -220,6 +223,7 @@ export const useFacilityCycleCount = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useQuery<
number,
Expand Down
14 changes: 12 additions & 2 deletions packages/datagateway-common/src/api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { useSelector } from 'react-redux';
import { StateType } from '../state/app.types';
import format from 'date-fns/format';
import { isValid } from 'date-fns';
import retryICATErrors from './retryICATErrors';
import { useRetryICATErrors } from './retryICATErrors';

export * from './cart';
export * from './facilityCycles';
Expand Down Expand Up @@ -678,6 +678,7 @@ export const useIds = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useQuery<
number[],
Expand Down Expand Up @@ -758,6 +759,7 @@ export const useCustomFilter = (
}[]
): UseQueryResult<string[], Error> => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const retryICATErrors = useRetryICATErrors();

return useQuery<
string[],
Expand Down Expand Up @@ -842,6 +844,7 @@ export const useCustomFilterCount = (
}[]
): UseQueryResult<number, AxiosError>[] => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const retryICATErrors = useRetryICATErrors();

const queryConfigs: UseQueryOptions<
number,
Expand Down Expand Up @@ -891,7 +894,14 @@ export const useCustomFilterCount = (
staleTime: Infinity,
};
});
}, [apiUrl, entityType, filterIds, filterKey, additionalFilters]);
}, [
filterIds,
entityType,
filterKey,
additionalFilters,
retryICATErrors,
apiUrl,
]);

// useQueries doesn't allow us to specify type info, so ignore this line
// since we strongly type the queries object anyway
Expand Down
6 changes: 5 additions & 1 deletion packages/datagateway-common/src/api/instruments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
useInfiniteQuery,
UseInfiniteQueryResult,
} from 'react-query';
import retryICATErrors from './retryICATErrors';
import { useRetryICATErrors } from './retryICATErrors';

const fetchInstruments = (
apiUrl: string,
Expand Down Expand Up @@ -62,6 +62,7 @@ export const useInstrumentsPaginated = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters, sort, page, results } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useQuery<
Instrument[],
Expand Down Expand Up @@ -112,6 +113,7 @@ export const useInstrumentsInfinite = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters, sort } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useInfiniteQuery(
['instrument', { sort: JSON.stringify(sort), filters }], // need to stringify sort as property order is important!
Expand Down Expand Up @@ -155,6 +157,7 @@ export const useInstrumentCount = (): UseQueryResult<number, AxiosError> => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useQuery<
number,
Expand Down Expand Up @@ -198,6 +201,7 @@ export const useInstrumentDetails = (
instrumentId: number
): UseQueryResult<Instrument, AxiosError> => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const retryICATErrors = useRetryICATErrors();

return useQuery<Instrument, AxiosError, Instrument, [string, number]>(
['instrumentDetails', instrumentId],
Expand Down
7 changes: 6 additions & 1 deletion packages/datagateway-common/src/api/investigations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
useQuery,
UseQueryResult,
} from 'react-query';
import retryICATErrors from './retryICATErrors';
import { useRetryICATErrors } from './retryICATErrors';

export const fetchInvestigations = (
apiUrl: string,
Expand Down Expand Up @@ -61,6 +61,7 @@ export const useInvestigation = (
additionalFilters?: AdditionalFilters
): UseQueryResult<Investigation[], AxiosError> => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const retryICATErrors = useRetryICATErrors();

return useQuery<
Investigation[],
Expand Down Expand Up @@ -97,6 +98,7 @@ export const useInvestigationsPaginated = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters, sort, page, results } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useQuery<
Investigation[],
Expand Down Expand Up @@ -158,6 +160,7 @@ export const useInvestigationsInfinite = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const { filters, sort } = parseSearchToQuery(location.search);
const retryICATErrors = useRetryICATErrors();

return useInfiniteQuery(
[
Expand Down Expand Up @@ -216,6 +219,7 @@ export const useInvestigationCount = (
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const location = useLocation();
const filters = parseSearchToQuery(location.search).filters;
const retryICATErrors = useRetryICATErrors();

return useQuery<
number,
Expand Down Expand Up @@ -267,6 +271,7 @@ export const useInvestigationDetails = (
investigationId: number
): UseQueryResult<Investigation, AxiosError> => {
const apiUrl = useSelector((state: StateType) => state.dgcommon.urls.apiUrl);
const retryICATErrors = useRetryICATErrors();

return useQuery<Investigation, AxiosError, Investigation, [string, number]>(
['investigationDetails', investigationId],
Expand Down
3 changes: 2 additions & 1 deletion packages/datagateway-common/src/api/lucene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '../app.types';
import handleICATError from '../handleICATError';
import { readSciGatewayToken } from '../parseTokens';
import retryICATErrors from './retryICATErrors';
import { useRetryICATErrors } from './retryICATErrors';

interface QueryParameters {
target: string;
Expand Down Expand Up @@ -352,6 +352,7 @@ export const useLuceneSearchInfinite = (
{}
);
}
const retryICATErrors = useRetryICATErrors();

return useInfiniteQuery(
['search', datasearchType, luceneParams],
Expand Down
Loading

0 comments on commit 309c2a7

Please sign in to comment.