UNPKG

adastra-ui-comment

Version:

Testing locally 1) in this file - `npm i` install dependencies - `npm run build` or `npm run tsc` to build your module 2) in childApp - in package.json under dependencies add ui-astra-assets with file:(relativePathToRepo) - "ui-astra-a

51 lines (41 loc) 1.54 kB
import { DiscoverySdk } from '@adastradev/serverless-discovery-sdk'; import Cache from '@aws-amplify/cache'; import { call } from 'redux-saga/effects'; import moment from 'moment'; /* * Return and cache the latest URI for a service. */ export default async function lookupService(serviceName, retry?) { if (!retry && Cache.getItem(`${serviceName}-uri`)) { return Cache.getItem(`${serviceName}-uri`); } const sdk = new DiscoverySdk( process.env.REACT_APP_SERVICE_DISCOVERY_URL as string, process.env.REACT_APP_SERVICE_DISCOVERY_REGION, process.env.REACT_APP_SERVICE_DISCOVERY_STAGE, undefined, // Require cloudDependencies in from package.json new Map(Object.entries(require('../../package.json')['cloudDependencies'])), ); const endpoints = await sdk.lookupService( serviceName, ); Cache.setItem(`${serviceName}-uri`, endpoints[0], { priority: 1, expires: moment().add(5, 'm').valueOf(), }); return endpoints[0]; } /* * We're hoping to reset our Cache'ed URI for the service because we recieved a * "not lastest service error". We want to check if the URI actually changed. Then * re-call the saga with it's action (data). */ export function* retrySagaWithNewService(serviceName, callBackSaga, callBackAction) { const pastEndpoint = Cache.getItem(`${serviceName}-uri`); const endpoint = yield call(lookupService, serviceName, true); if (pastEndpoint === endpoint) { throw 'Service URI has not changed'; } yield call(callBackSaga, callBackAction); }