• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanopub-registry / 22892118311

10 Mar 2026 07:39AM UTC coverage: 27.147% (-0.03%) from 27.177%
22892118311

push

github

tkuhn
feat: show currently running task on /debug/tasks page

Track the active task name and start time in Task so the debug endpoint
can display what is running and for how long.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

170 of 686 branches covered (24.78%)

Branch coverage included in aggregate %.

554 of 1981 relevant lines covered (27.97%)

4.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/main/java/com/knowledgepixels/registry/DebugPage.java
1
package com.knowledgepixels.registry;
2

3
import com.mongodb.client.ClientSession;
4
import com.mongodb.client.MongoCursor;
5
import io.vertx.ext.web.RoutingContext;
6
import org.bson.Document;
7

8
import java.io.IOException;
9

10
import static com.knowledgepixels.registry.RegistryDB.collection;
11
import static com.mongodb.client.model.Indexes.ascending;
12

13
public class DebugPage extends Page {
14

15
    public static void show(RoutingContext context) {
16
        DebugPage page;
17
        try (ClientSession s = RegistryDB.getClient().startSession()) {
×
18
            s.startTransaction();
×
19
            page = new DebugPage(s, context);
×
20
            page.show();
×
21
        } catch (IOException ex) {
×
22
            ex.printStackTrace();
×
23
        } finally {
24
            context.response().end();
×
25
            // TODO Clean-up here?
26
        }
27
    }
×
28

29
    private DebugPage(ClientSession mongoSession, RoutingContext context) {
30
        super(mongoSession, context);
×
31
    }
×
32

33
    protected void show() throws IOException {
34
        RoutingContext c = getContext();
×
35

36
        if (getRequestString().matches("/debug/trustPaths")) {
×
37
            String counterString = c.request().getParam("trustStateCounter");
×
38
            if (counterString == null) {
×
39
                print(getTrustPathsTxt(mongoSession));
×
40
            } else {
41
                Long counter = Long.parseLong(counterString);
×
42
                print(RegistryDB.getOne(mongoSession, "debug_trustPaths", new Document("trustStateCounter", counter)).getString("trustStateTxt"));
×
43
            }
44
            setRespContentType("text/plain");
×
45
        } else if (getRequestString().matches("/debug/endorsements")) {
×
46
            MongoCursor<Document> tp = collection("endorsements").find(mongoSession).cursor();
×
47
            while (tp.hasNext()) {
×
48
                Document d = tp.next();
×
49
                println(d.get("agent") + ">" + d.get("pubkey") + " " + d.get("endorsedNanopub") + " " + d.get("source") + " (" + d.get("status") + ")");
×
50
            }
×
51
            setRespContentType("text/plain");
×
52
        } else if (getRequestString().matches("/debug/accounts")) {
×
53
            MongoCursor<Document> tp = collection("accounts").find(mongoSession).cursor();
×
54
            while (tp.hasNext()) {
×
55
                Document d = tp.next();
×
56
                println(d.getString("agent") + ">" + d.get("pubkey") + " " + d.get("depth") + " (" + d.get("status") + ")");
×
57
            }
×
58
        } else if (getRequestString().matches("/debug/tasks")) {
×
59
            setRespContentType("text/plain");
×
60
            try {
61
                String currentTask = Task.getCurrentTaskName();
×
62
                if (currentTask != null) {
×
63
                    long elapsed = System.currentTimeMillis() - Task.getCurrentTaskStartTime();
×
64
                    println("Currently running: " + currentTask + " (for " + elapsed + "ms)");
×
65
                } else {
×
66
                    println("Currently running: (none)");
×
67
                }
68
                println("");
×
69
                MongoCursor<Document> tasks = collection(Collection.TASKS.toString()).find(mongoSession)
×
70
                        .sort(ascending("not-before")).cursor();
×
71
                int count = 0;
×
72
                while (tasks.hasNext()) {
×
73
                    println(tasks.next().toJson());
×
74
                    count++;
×
75
                }
76
                println("Total queued tasks: " + count);
×
77
            } catch (Exception ex) {
×
78
                println("Error: " + ex.getClass().getName() + ": " + ex.getMessage());
×
79
            }
×
80
        } else if (getRequestString().matches("/debug/peerState")) {
×
81
            setRespContentType("text/plain");
×
82
            try {
83
                long count = collection(Collection.PEER_STATE.toString()).countDocuments(mongoSession);
×
84
                println("peerState documents: " + count);
×
85
                MongoCursor<Document> ps = collection(Collection.PEER_STATE.toString()).find(mongoSession).cursor();
×
86
                while (ps.hasNext()) {
×
87
                    println(ps.next().toJson());
×
88
                }
89
            } catch (Exception ex) {
×
90
                println("Error: " + ex.getClass().getName() + ": " + ex.getMessage());
×
91
            }
×
92
        } else {
93
            c.response().setStatusCode(400).setStatusMessage("Invalid request: " + getFullRequest());
×
94
        }
95
    }
×
96

97
    public static String getTrustPathsTxt(ClientSession mongoSession) {
98
        String s = "";
×
99
        MongoCursor<Document> tp = collection("trustPaths").find(mongoSession).sort(ascending("_id")).cursor();
×
100
        while (tp.hasNext()) {
×
101
            Document d = tp.next();
×
102
            String path = d.getString("_id");
×
103
            path = path.replace(" ", " > ");
×
104
            if (d.getString("type").equals("extended")) {
×
105
                path = path.replaceFirst(" > ([^ ]+)$", " ~ $1");
×
106
            }
107
            s += path + "\n";
×
108
        }
×
109
        return s;
×
110
    }
111

112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc