Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary production debug #446

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ COPY . .
RUN yarn papi
RUN yarn build

CMD yarn migrations:run && yarn start
CMD yarn migrations:run && yarn start || ./papi-log-printer.sh
7 changes: 7 additions & 0 deletions papi-log-printer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

echo "Exited with non-zero code; latest 100 lines of papi-debug-inner.log:"
tail -n 100 papi-debug-inner.log

echo "latest 100 lines of papi-debug-outer.log:"
tail -n 100 papi-debug-outer.log
24 changes: 14 additions & 10 deletions src/papi/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { config } from "#src/config";
import fs from "fs";
import { createClient, PolkadotClient } from "polkadot-api";
import { withLogsRecorder } from "polkadot-api/logs-provider";
import { fixUnorderedBlocks, parsed } from "polkadot-api/polkadot-sdk-compat";
import { withPolkadotSdkCompat } from "polkadot-api/polkadot-sdk-compat";
import { getWsProvider, JsonRpcProvider } from "polkadot-api/ws-provider/node";

import { getNetworkData } from "./chains";
Expand All @@ -12,13 +12,17 @@ const networkData = getNetworkData(networkName);

let provider: JsonRpcProvider = getWsProvider(networkData.data.rpcEndpoint);

if (process.env.PAPI_DEBUG) {
// Sync appends aren't ideal, but otherwise, we wouldn't be able to export client,
// without wrapping it in a promise. For debug, good enough.
fs.writeFileSync("papi-debug.log", "");
provider = withLogsRecorder((msg) => {
fs.appendFileSync("papi-debug.log", `${msg}\n`);
}, provider);
}
// Sync appends aren't ideal, but otherwise, we wouldn't be able to export client,
// without wrapping it in a promise. For debug, good enough.
fs.writeFileSync("papi-debug-inner.log", "");
fs.writeFileSync("papi-debug-outer.log", "");

export const client: PolkadotClient = createClient(parsed(fixUnorderedBlocks)(provider));
provider = withLogsRecorder((msg) => {
fs.appendFileSync("papi-debug-inner.log", `${msg}\n`);
}, provider);

provider = withLogsRecorder((msg) => {
fs.appendFileSync("papi-debug-outer.log", `${msg}\n`);
}, withPolkadotSdkCompat(provider));

export const client: PolkadotClient = createClient(provider);
Loading