Skip to content

Commit

Permalink
Merge branch 'log_passport_reset' into 811-passport-reset-with-stamps
Browse files Browse the repository at this point in the history
  • Loading branch information
nutrina committed Jan 20, 2023
2 parents 6d293b8 + 0ed5d92 commit 9ab4327
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
16 changes: 15 additions & 1 deletion app/components/RefreshStampModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { CeramicContext } from "../context/ceramicContext";
import { Progress, completedIcon, Status, Step } from "./Progress";
import { useToast } from "@chakra-ui/react";

// --- Datadog
import { datadogLogs } from "@datadog/browser-logs";

export type RefreshStampModalProps = {
isOpen: boolean;
onClose: () => void;
};

export const RefreshStampModal = ({ isOpen, onClose }: RefreshStampModalProps) => {
const { handleCheckRefreshPassport } = useContext(CeramicContext);
const { handleCheckRefreshPassport, userDid } = useContext(CeramicContext);
const [resetError, setResetError] = useState<boolean>(false);
const toast = useToast();

Expand Down Expand Up @@ -64,15 +67,26 @@ export const RefreshStampModal = ({ isOpen, onClose }: RefreshStampModalProps) =
const refreshPassportState = async () => {
try {
updateSteps(1);
datadogLogs.logger.info(`RefreshStampModal - calling handleCheckRefreshPassport for did=${userDid}`, {
did: userDid,
});
const refreshSuccess = await handleCheckRefreshPassport();
// If errors were found while refreshing they won't be filtered out
if (!refreshSuccess) {
datadogLogs.logger.error(
`RefreshStampModal - calling handleCheckRefreshPassport was not successfull for did=${userDid}`,
{ did: userDid }
);
// handleCheckRefreshPassport returned an error after polling ceramic
updateSteps(2, true);
// show error status in progress bar for 2 seconds
await new Promise((resolve) => setTimeout(resolve, 2000));
setResetError(true);
} else {
datadogLogs.logger.info(
`RefreshStampModal - calling handleCheckRefreshPassport was successfull for did=${userDid}`,
{ did: userDid }
);
updateSteps(2);
// Wait 2 seconds to show success toast
await new Promise((resolve) => setTimeout(resolve, 2000));
Expand Down
1 change: 0 additions & 1 deletion app/context/userContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ export const UserContextProvider = ({ children }: { children: any }) => {
})
);
const session = await DIDSession.authorize(authMethod, {
expiresInSecs: 24 * 3600,
resources: ["ceramic://*"],
});
const newSessionStr = session.serialize();
Expand Down
14 changes: 9 additions & 5 deletions database-client/src/ceramicClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class CeramicDatabase implements DataStorageBase {
const rest = await axios.get(streamUrl);
return false;
} catch (e) {
this.logger.error(`Error when calling getRecordDocument on Passport`, e);
this.logger.error(`checkPassportCACAOError - Error when calling getRecordDocument on Passport`, {error:e});
if (e?.response?.data?.error?.includes("CACAO has expired")) {
return true;
}
Expand All @@ -124,20 +124,24 @@ export class CeramicDatabase implements DataStorageBase {

let passportDoc;
try {
this.logger.info("refreshPassport - getRecordDocument");
passportDoc = await this.store.getRecordDocument(this.model.getDefinitionID("Passport"));
} catch (e) {
this.logger.info("refreshPassport - failed to get record document", {error:e});
// unable to get passport doc
return false;
}
// Attempt to load stream 36 times, with 5 second delay between each attempt - 5 min total
while (attempts < 36 && !success) {
const options = attempts === 1 ? { sync: SyncOptions.SYNC_ALWAYS, syncTimeoutSeconds: 5 } : {};
try {
this.logger.info(`refreshPassport - loading stream with SyncOptions.SYNC_ALWAYS, attempt:${attempts}, stream=${passportDoc.id}`, {options:options});
await this.ceramicClient.loadStream<TileDocument>(passportDoc.id, options);
success = true;
this.logger.info(`refreshPassport - loading stream with SyncOptions.SYNC_ALWAYS, attempt:${attempts}, stream=${passportDoc.id} => SUCCESS`);
return success;
} catch (e) {
this.logger.error(`Error when calling loadStream on passport, attempt ${attempts}`, e);
this.logger.error(`refreshPassport - error when calling loadStream on passport, attempt ${attempts}`, {error: e});
attempts++;
await new Promise((resolve) => setTimeout(resolve, 5000));
}
Expand Down Expand Up @@ -182,7 +186,7 @@ export class CeramicDatabase implements DataStorageBase {
errors.error = true;
}
this.logger.error(
`Error when loading stamp with streamId ${streamIDs[idx]} for did ${this.did}:` + e.toString()
`Error when loading stamp with streamId ${streamIDs[idx]} for did ${this.did}:` + e.toString(), {error: e}
);
throw e;
}
Expand All @@ -207,15 +211,15 @@ export class CeramicDatabase implements DataStorageBase {
const passportDoc = await this.store.getRecordDocument(this.model.getDefinitionID("Passport"));
await this.ceramicClient.pin.add(passportDoc.id);
} catch (e) {
this.logger.error(`Error when pinning passport for did ${this.did}:` + e.toString());
this.logger.error(`Error when pinning passport for did ${this.did}:` + e.toString(), {error: e});
}

return {
passport: parsedPassport,
errors,
};
} catch (e) {
this.logger.error(`Error when loading passport for did ${this.did}:` + e.toString());
this.logger.error(`Error when loading passport for did ${this.did}:` + e.toString(), {error: e});
// Indicate there was an error loading passport
errors.error = true;
errors.passport = true;
Expand Down
2 changes: 1 addition & 1 deletion infra/ceramic-testnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ const service = new awsx.ecs.FargateService("dpopp-ceramic", {
taskDefinitionArgs: {
containers: {
ceramic: {
image: "ceramicnetwork/js-ceramic:2.6.1-rc.2",
image: "ceramicnetwork/js-ceramic:2.18.0",
memory: 8192,
cpu: 4096,
portMappings: [httpsListener],
Expand Down

0 comments on commit 9ab4327

Please sign in to comment.