mirror of
https://github.com/stronk-dev/OrchestratorTracker.git
synced 2025-07-05 02:45:10 +02:00
Write to storage only once after processing the entire queue
This commit is contained in:
parent
0f30cf4a27
commit
12bb7c01f4
@ -76,6 +76,8 @@ let lastLeaderboardCheck = 0;
|
|||||||
let lastStringify = 0;
|
let lastStringify = 0;
|
||||||
let isSynced = false;
|
let isSynced = false;
|
||||||
let storageLock = false;
|
let storageLock = false;
|
||||||
|
let staleENSCache = false;
|
||||||
|
let staleOrchCache = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Function Skeletons
|
* Function Skeletons
|
||||||
@ -100,11 +102,10 @@ async function withStorageLock(fn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function safeWrite(key, data) {
|
async function writeToStorage(key, data) {
|
||||||
const tempKey = `${key}.tmp`;
|
await withStorageLock(async () => {
|
||||||
await storage.setItem(tempKey, data); // Write to temp key
|
await storage.setItem(key, data);
|
||||||
await storage.removeItem(key); // Remove original key
|
});
|
||||||
await storage.setItem(key, data); // Rename temp key to original
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process the task queue continuously
|
// Process the task queue continuously
|
||||||
@ -118,6 +119,12 @@ async function processQueue() {
|
|||||||
console.error("Error processing task:", error);
|
console.error("Error processing task:", error);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (staleENSCache) {
|
||||||
|
await writeToStorage("ensDomainCache", ensDomainCache);
|
||||||
|
}
|
||||||
|
if (staleOrchCache) {
|
||||||
|
await writeToStorage("orchCache", orchCache);
|
||||||
|
}
|
||||||
await sleep(1000);
|
await sleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,9 +168,7 @@ async function getEnsDomain(addr) {
|
|||||||
ensObj.timestamp
|
ensObj.timestamp
|
||||||
);
|
);
|
||||||
ensDomainCache[addr] = ensObj;
|
ensDomainCache[addr] = ensObj;
|
||||||
await withStorageLock(async () => {
|
staleENSCache = true;
|
||||||
await safeWrite("ensDomainCache", ensDomainCache);
|
|
||||||
});
|
|
||||||
if (ensObj.domain) {
|
if (ensObj.domain) {
|
||||||
// Update domain name
|
// Update domain name
|
||||||
return ensObj.domain;
|
return ensObj.domain;
|
||||||
@ -405,9 +410,7 @@ async function onOrchUpdate(id, obj, tag, region, livepeer_regions) {
|
|||||||
newObj.instances[obj.resolv.resolvedTarget] = newInstance;
|
newObj.instances[obj.resolv.resolvedTarget] = newInstance;
|
||||||
newObj.regionalStats[tag] = newRegion;
|
newObj.regionalStats[tag] = newRegion;
|
||||||
orchCache[id.toLowerCase()] = newObj;
|
orchCache[id.toLowerCase()] = newObj;
|
||||||
await withStorageLock(async () => {
|
staleOrchCache = true;
|
||||||
await safeWrite("orchCache", orchCache);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Update prometheus stats
|
// Update prometheus stats
|
||||||
updatePrometheus(tag, obj.resolv.resolvedTarget, newObj);
|
updatePrometheus(tag, obj.resolv.resolvedTarget, newObj);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user