mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2025-07-06 04:51:44 -07:00
fix: ping peer response handling
causes treating all members online fix async/await usage
This commit is contained in:
parent
8785b94392
commit
db8f4979e6
2 changed files with 18 additions and 14 deletions
|
@ -65,9 +65,9 @@ if (process.env.ZU_LAST_SEEN_FETCH !== "false") {
|
||||||
cron.schedule(schedule, () => {
|
cron.schedule(schedule, () => {
|
||||||
console.debug("Running scheduled job");
|
console.debug("Running scheduled job");
|
||||||
const networks = db.get("networks").value();
|
const networks = db.get("networks").value();
|
||||||
networks.forEach((network) => {
|
networks.forEach(async (network) => {
|
||||||
console.debug("Processing " + network.id);
|
console.debug("Processing network " + network.id);
|
||||||
pingAll(network);
|
await pingAll(network);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,26 @@
|
||||||
|
const _ = require("lodash");
|
||||||
|
|
||||||
const api = require("./controller-api");
|
const api = require("./controller-api");
|
||||||
const db = require("./db");
|
const db = require("./db");
|
||||||
|
|
||||||
async function pingAll(network) {
|
async function pingAll(network) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
network.members.map(async (member) => {
|
network.members.map(async (member) => {
|
||||||
console.debug("Processing " + member.id);
|
console.debug("Processing member " + member.id);
|
||||||
api
|
api
|
||||||
.get("peer/" + member.id)
|
.get("peer/" + member.id)
|
||||||
.then(async function () {
|
.then(function (controllerResp) {
|
||||||
// write lastOneline field in db
|
if (!_.isEmpty(controllerResp.data)) {
|
||||||
db.get("networks")
|
// write lastOnline field in db
|
||||||
.filter({ id: network.id })
|
db.get("networks")
|
||||||
.map("members")
|
.filter({ id: network.id })
|
||||||
.first()
|
.map("members")
|
||||||
.filter({ id: member.id })
|
.first()
|
||||||
.first()
|
.filter({ id: member.id })
|
||||||
.set("lastOnline", new Date().getTime())
|
.first()
|
||||||
.write();
|
.set("lastOnline", new Date().getTime())
|
||||||
|
.write();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
console.debug("Couldn't fetch", member.id);
|
console.debug("Couldn't fetch", member.id);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue