@weiping/mbridge-page 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/page/app.js +17 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weiping/mbridge-page",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "mbridge's usage at a glance inside magpie: what magpie's ledger recorded, and where mbridge's own status page is.",
5
5
  "license": "MIT",
6
6
  "keywords": [
package/page/app.js CHANGED
@@ -196,6 +196,9 @@
196
196
  async function readOptions() {
197
197
  try {
198
198
  const o = (await magpie.options.get()) || {};
199
+ // what we write back must be what we just read: writing a stale
200
+ // copy would put an old snapshot back
201
+ opts = o;
199
202
  if (V.PERIODS.includes(o.period)) state.period = o.period;
200
203
  if (V.SORTS.includes(o.sort)) state.sort = o.sort;
201
204
  state.mbridge = o.mbridge || null;
@@ -204,14 +207,19 @@
204
207
  }
205
208
  }
206
209
 
207
- async function load() {
208
- await readOptions();
210
+ // loadUsage reads what magpie recorded; it moves slowly.
211
+ async function loadUsage() {
209
212
  try {
210
213
  state.summary = await magpie.read("usage:summary", { period: state.period });
211
214
  state.error = null;
212
215
  } catch (e) {
213
216
  state.error = (e && e.message) || String(e);
214
217
  }
218
+ }
219
+
220
+ async function load() {
221
+ await readOptions();
222
+ await loadUsage();
215
223
  paint();
216
224
  }
217
225
 
@@ -296,5 +304,11 @@
296
304
  });
297
305
  words();
298
306
  await load();
299
- setInterval(load, 60000);
307
+ // magpie's ledger moves slowly; mbridge's snapshot moves every fifteen
308
+ // seconds, and reading the options is free
309
+ setInterval(loadUsage, 60000);
310
+ setInterval(async () => {
311
+ await readOptions();
312
+ paintMbridge();
313
+ }, 5000);
300
314
  })();