feat: add getRandomCid utility to retrieve a random CID for pinner job

This commit is contained in:
besoeasy
2026-01-01 20:23:12 +05:30
parent ec8d27413c
commit af2820efea
+20
View File
@@ -329,6 +329,26 @@ const cleanupStaleInProgress = () => {
}
};
// Get a random CID for pinner job
const getRandomCid = () => {
try {
// Get all CIDs that are not in progress
const availablePins = Array.from(pinsMap.values())
.filter(pin => !inProgressMap.has(pin.cid));
if (availablePins.length === 0) {
return null;
}
// Return a random pin
const randomIndex = Math.floor(Math.random() * availablePins.length);
return availablePins[randomIndex];
} catch (err) {
console.error(`[DB] Failed to get random CID:`, err.message);
return null;
}
};
// State management functions
const getLastPinnerActivity = () => lastPinnerActivity;
const setLastPinnerActivity = (timestamp) => {