From 9f23fbccbc6bc6f7330e2a96aa19f391bd1355ca Mon Sep 17 00:00:00 2001 From: dskvr Date: Sun, 17 Mar 2024 03:17:46 +0100 Subject: [PATCH] remove completed from queue --- apps/nocapd/Dockerfile | 2 +- apps/nocapd/src/classes/Worker.js | 12 +++++++----- apps/nocapd/src/daemon.js | 10 ++++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/apps/nocapd/Dockerfile b/apps/nocapd/Dockerfile index 94614651..3dd59e83 100644 --- a/apps/nocapd/Dockerfile +++ b/apps/nocapd/Dockerfile @@ -4,4 +4,4 @@ RUN mkdir /app WORKDIR /app COPY . . RUN yarn install -CMD yarn launch \ No newline at end of file +CMD node src/index.js \ No newline at end of file diff --git a/apps/nocapd/src/classes/Worker.js b/apps/nocapd/src/classes/Worker.js index c6040fbe..b45a9c95 100644 --- a/apps/nocapd/src/classes/Worker.js +++ b/apps/nocapd/src/classes/Worker.js @@ -64,10 +64,8 @@ export class NWWorker { setupJobOpts(){ this.jobOpts ={ - removeOnComplete: { - age: Math.round(this.expires/1000), - }, - removeOnFail: 11, + removeOnComplete: true, + removeOnFail: true } } @@ -347,6 +345,8 @@ export class NWWorker { this.relayMeta = new Map() for (const relay of allRelays) { + if(!this.qualifyNetwork(relay.url)) continue + this.log.debug(`getRelays() relay: ${relay.url}`) this.log.debug(`getRelays() relay: ${relay.url}: lastChecked()`) @@ -375,9 +375,11 @@ export class NWWorker { this.log.info(`online: ${await this.rcache.relay.get.online()?.length}, \ online & expired: ${onlineRelays.length}, \ - expired: ${expiredRelays.length}, \ + expired: ${expiredRelays.filter(this.qualifyNetwork.bind(this)).length}, \ unchecked: ${uncheckedRelays.filter(this.qualifyNetwork.bind(this)).length}, \ total: ${allRelays.length}`); + + console.log('!!! expired relays', expiredRelays) const deduped = [...new Set([...onlineRelays, ...uncheckedRelays, ...expiredRelays])]; const relaysFiltered = deduped.filter(this.qualifyNetwork.bind(this)); diff --git a/apps/nocapd/src/daemon.js b/apps/nocapd/src/daemon.js index 4688e094..85f45e8a 100644 --- a/apps/nocapd/src/daemon.js +++ b/apps/nocapd/src/daemon.js @@ -21,6 +21,8 @@ const log = new Logger('@nostrwatch/nocapd') let rcache let config let $q +let intervalPopulate +let intervalSyncRelays const populateQueue = async () => { log.info(`drained: ${$q.queue.name}`) @@ -37,6 +39,11 @@ const checkQueue = async () => { await populateQueue() } +const setIntervals = () => { + intervalSyncRelays = setInterval( syncRelaysIn, timestring(config?.nocapd?.seed?.options?.events?.interval, "ms") || timestring("1h", "ms")) + intervalPopulate = setInterval( checkQueue, timestring( "1m", "ms" )) +} + const initWorker = async () => { const connection = RedisConnectionDetails() const concurrency = config?.nocapd?.bullmq?.worker?.concurrency? config.nocapd.bullmq.worker.concurrency: 1 @@ -49,8 +56,7 @@ const initWorker = async () => { .set( 'worker' , new BullMQ.Worker($q.queue.name, $q.route_work.bind($q), { concurrency, connection, ...queueOpts() } ) ) .drain() await $q.obliterate().catch(()=>{}) - setInterval( syncRelaysIn, timestring(config?.nocapd?.seed?.options?.events?.interval, "ms") || timestring("1h", "ms")) - setInterval( checkQueue, timestring( "1m", "ms" )) + setIntervals() // $q.events.on('drained', populateQueue) await populateQueue() $q.resume()