Skip to content

Commit

Permalink
update healthcheck; add metrics config
Browse files Browse the repository at this point in the history
  • Loading branch information
alecananian committed Jul 11, 2024
1 parent 2234c7e commit c9461ac
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
23 changes: 18 additions & 5 deletions app/api/tokens.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,32 @@ import {
} from ".graphclient";

/**
* Fetches tokens available for swapping with NFT metadata and USD prices
* Fetches tokens available for swapping
*/
export const fetchTokens = async () => {
const result = (await execute(
const { data, errors } = (await execute(
GetTokensDocument,
{},
)) as ExecutionResult<GetTokensQuery>;
const { tokens: rawTokens = [] } = result.data ?? {};
if (errors) {
throw new Error(
`Error fetching tokens: ${errors.map((error) => error.message).join(", ")}`,
);
}

return data?.tokens ?? [];
};

/**
* Fetches tokens available for swapping with NFT metadata and USD prices
*/
export const fetchTokensWithMetadata = async () => {
const tokens = await fetchTokens();
const [[collectionMapping, tokenMapping], magicUSD] = await Promise.all([
fetchTokensCollections(rawTokens),
fetchTokensCollections(tokens),
fetchMagicUSD(),
]);
return rawTokens.map((token) =>
return tokens.map((token) =>
createPoolToken(token, collectionMapping, tokenMapping, magicUSD),
);
};
Expand Down
12 changes: 11 additions & 1 deletion app/routes/healthcheck.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
export const loader = () => new Response("OK");
import { fetchTokens } from "~/api/tokens.server";

export const loader = async () => {
try {
await fetchTokens();
return new Response("OK");
} catch (err) {
console.error("Healthcheck failed:", err);
return new Response("ERROR", { status: 500 });
}
};
3 changes: 2 additions & 1 deletion app/routes/swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
fetchPoolTokenBalance,
fetchToken,
fetchTokens,
fetchTokensWithMetadata,
} from "~/api/tokens.server";
import { CurrencyInput } from "~/components/CurrencyInput";
import { DisabledInputPopover } from "~/components/DisabledInputPopover";
Expand Down Expand Up @@ -114,7 +115,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
const address = session.get("address");
return defer({
pools,
tokens: fetchTokens(),
tokens: fetchTokensWithMetadata(),
tokenIn,
tokenOut,
tokenInNFTBalance:
Expand Down
4 changes: 4 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ primary_region = "lax"
path = "/healthcheck"
protocol = "http"
tls_skip_verify = false

[metrics]
port = 9090
path = "/metrics"

0 comments on commit c9461ac

Please sign in to comment.