MCPcopy Index your code
hub / github.com/kopia/kopia / pollOnce

Function pollOnce

app/public/server.js:76–127  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

74 const pollInterval = 3000;
75
76 function pollOnce() {
77 if (
78 !runningServerAddress ||
79 !runningServerCertificate ||
80 !runningServerPassword ||
81 !runningServerControlPassword
82 ) {
83 return;
84 }
85
86 const req = https.request(
87 {
88 ca: [runningServerCertificate],
89 host: "127.0.0.1",
90 port: parseInt(new URL(runningServerAddress).port),
91 method: "GET",
92 path: "/api/v1/control/status",
93 timeout: pollInterval,
94 headers: {
95 Authorization:
96 "Basic " +
97 Buffer.from(
98 "server-control" + ":" + runningServerControlPassword,
99 ).toString("base64"),
100 },
101 },
102 (resp) => {
103 if (resp.statusCode === 200) {
104 resp.on("data", (x) => {
105 try {
106 const newDetails = JSON.parse(x);
107 if (
108 JSON.stringify(newDetails) !=
109 JSON.stringify(runningServerStatusDetails)
110 ) {
111 runningServerStatusDetails = newDetails;
112 statusUpdated();
113 }
114 } catch (e) {
115 log.warn("unable to parse status JSON", e);
116 }
117 });
118 } else {
119 log.warn("error fetching status", resp.statusMessage);
120 }
121 },
122 );
123 req.on("error", (e) => {
124 log.info("error fetching status", e);
125 });
126 req.end();
127 }
128
129 const statusPollInterval = setInterval(pollOnce, pollInterval);
130

Callers

nothing calls this directly

Calls 2

infoMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected