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

fix: Report status for empty db #503

Merged
merged 3 commits into from
Dec 20, 2024
Merged
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
43 changes: 22 additions & 21 deletions services/gatekeeper/server/src/gatekeeper-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,29 +295,30 @@ async function reportStatus() {
console.log(`DID Database (${config.db}):`);
console.log(` Total: ${status.dids.total}`);

console.log(` By type:`);
console.log(` Agents: ${status.dids.byType.agents}`);
console.log(` Assets: ${status.dids.byType.assets}`);
console.log(` Confirmed: ${status.dids.byType.confirmed}`);
console.log(` Unconfirmed: ${status.dids.byType.unconfirmed}`);
console.log(` Ephemeral: ${status.dids.byType.ephemeral}`);
console.log(` Invalid: ${status.dids.byType.invalid}`);

console.log(` By registry:`);
const registries = Object.keys(status.dids.byRegistry).sort();
for (let registry of registries) {
console.log(` ${registry}: ${status.dids.byRegistry[registry]}`);
}
if (status.dids.total > 0) {
console.log(` By type:`);
console.log(` Agents: ${status.dids.byType.agents}`);
console.log(` Assets: ${status.dids.byType.assets}`);
console.log(` Confirmed: ${status.dids.byType.confirmed}`);
console.log(` Unconfirmed: ${status.dids.byType.unconfirmed}`);
console.log(` Ephemeral: ${status.dids.byType.ephemeral}`);
console.log(` Invalid: ${status.dids.byType.invalid}`);

console.log(` By registry:`);
const registries = Object.keys(status.dids.byRegistry).sort();
for (let registry of registries) {
console.log(` ${registry}: ${status.dids.byRegistry[registry]}`);
}

console.log(` By version:`);
let count = 0;
for (let version of [1, 2, 3, 4, 5]) {
const num = status.dids.byVersion[version];
console.log(` ${version}: ${num}`);
count += num;
console.log(` By version:`);
let count = 0;
for (let version of [1, 2, 3, 4, 5]) {
const num = status.dids.byVersion[version] || 0;
console.log(` ${version}: ${num}`);
count += num;
}
console.log(` 6+: ${status.dids.total - count}`);
}
console.log(` 6+: ${status.dids.total - count}`);


console.log(`Memory Usage Report:`);
console.log(` RSS: ${formatBytes(status.memoryUsage.rss)} (Resident Set Size - total memory allocated for the process)`);
Expand Down
40 changes: 27 additions & 13 deletions services/keymaster/server/src/keymaster-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,31 @@ process.on('unhandledRejection', (reason, promise) => {
//console.error('Unhandled rejection caught');
});

async function waitForCurrentId() {
let isReady = false;
const currentId = await keymaster.getCurrentId();

if (!currentId) {
return;
}

while (!isReady) {
try {
console.log(`Resolving current ID: ${currentId}`);
const doc = await keymaster.resolveDID(currentId);
console.log(JSON.stringify(doc, null, 4));
isReady = true;
}
catch {
console.log(`Waiting for gatekeeper to sync...`);
}

if (!isReady) {
await new Promise(resolve => setTimeout(resolve, 10000));
}
}
}

const port = config.keymasterPort;

app.listen(port, async () => {
Expand All @@ -707,17 +732,6 @@ app.listen(port, async () => {
await keymaster.start({ gatekeeper, wallet, cipher });
console.log(`keymaster server running on port ${port}`);

try {
const currentId = await keymaster.getCurrentId();

if (currentId) {
console.log(`current ID: ${currentId}`);
const doc = await keymaster.resolveId();
console.log(JSON.stringify(doc, null, 4));
}
serverReady = true;
}
catch (error) {
console.log(error);
}
await waitForCurrentId();
serverReady = true;
});
Loading