Skip to content

Commit

Permalink
fix: Report status for empty db (#503)
Browse files Browse the repository at this point in the history
* Include DID stats only when available

* keymaster waits for gatekeeper to sync
  • Loading branch information
macterra authored Dec 20, 2024
1 parent 8f9ec02 commit a6ded54
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 34 deletions.
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;
});

0 comments on commit a6ded54

Please sign in to comment.