From 8165349da2f328bddd626bc8b3728e1f6dd8c785 Mon Sep 17 00:00:00 2001 From: dskvr Date: Sun, 17 Mar 2024 00:33:12 +0100 Subject: [PATCH] fix controlflow dep in nocapd --- apps/nocapd/src/classes/Worker.js | 25 +++++++++++++------------ apps/nocapd/src/index.js | 21 ++++++++++++++++++++- packages/controlflow/package.json | 4 ++-- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/apps/nocapd/src/classes/Worker.js b/apps/nocapd/src/classes/Worker.js index b4f550ba..dcbb6c19 100644 --- a/apps/nocapd/src/classes/Worker.js +++ b/apps/nocapd/src/classes/Worker.js @@ -29,7 +29,7 @@ export class NWWorker { setupDefaultValues(){ this.cb = {} - this.processed = 0 + this.processed = 1 this.total = 0 this.relayMeta = new Map() this.jobOpts = {} @@ -79,14 +79,12 @@ export class NWWorker { async populator(){ this.log.info(`populator()`) await this.$.worker.pause() - this.log.debug(`populator(): worker paused`) const relays = await this.getRelays() - this.log.debug(`populator(): adding ${relays.length} relays to queue`) - await this.addRelayJobs(relays) - this.log.debug(`populator(): added ${relays.length} relays to queue`) + if(relays.length > 0) + await this.addRelayJobs(relays) + else + this.setTimeout( this.populator.bind(this), this.interval) await this.$.worker.resume() - this.log.debug(`populator(): worker resumed`) - } async work(job){ @@ -109,6 +107,7 @@ export class NWWorker { this.log.debug(`on_completed(): ${job.id}: ${JSON.stringify(rvalue)}`) const { result } = rvalue let fail = result?.open?.data? false: true + this.progressMessage(result.url, result, fail) if(fail) await this.on_fail( result ) else @@ -147,8 +146,6 @@ export class NWWorker { await this.retry.setRetries( result.url, !error ) await delay(100) await this.setLastChecked( result.url, Date.now() ) - - this.progressMessage(result.url, result, error) } cbcall(...args){ @@ -171,8 +168,8 @@ export class NWWorker { async resetProgressCounts(){ const c = await this.counts() - this.total = c.prioritized - this.processed = 0 + this.total = c.prioritized + c.active + this.processed = 1 this.log.debug(`total jobs: ${this.total}`) } @@ -318,7 +315,11 @@ export class NWWorker { const resultHasKey = result?.[key]?.data && Object.keys(result[key].data)?.length > 0 if(resultHasKey){ const persist_result = async (resolve, reject) => { - const _record = { url: url, relay_id, updated_at: Date.now(), hash: hash(result[key].data), data: JSON.stringify(result[key].data) } + this.log.debug(`persist_result(${key})`) + + const _record = { url: url, relay_id, updated_at: Date.now(), hash: hash(result[key].data) } + if(key === 'ssl') _record.data = JSON.stringify({ valid_to: result[key].data.valid_to, valid_from: result[key].data.valid_from }) + else _record.data = JSON.stringify(result[key].data) const _check_id = await this.rcache.check[key].insert(_record) if(!_check_id) reject() diff --git a/apps/nocapd/src/index.js b/apps/nocapd/src/index.js index 56ea7179..fdd96f32 100644 --- a/apps/nocapd/src/index.js +++ b/apps/nocapd/src/index.js @@ -51,4 +51,23 @@ async function gracefulShutdown(signal) { process.exit(9); } -const $d = await run() \ No newline at end of file +const $d = await run() + + +import { createRequire } from 'module'; +import path from 'path'; + +const require = createRequire(import.meta.url); +const nodeModulesPath = path.join(process.cwd(), 'node_modules'); +const dependencies = require('../package.json').dependencies; + +for (const dep of Object.keys(dependencies)) { + if(!dep.startsWith('@nostrwatch')) continue; + try { + const packageJsonPath = path.join(nodeModulesPath, dep, 'package.json'); + const packageJson = require(packageJsonPath); // Using require from 'module' for JSON + console.log(`${dep}: ${packageJson.version}`); + } catch (error) { + console.error(`Could not read version for dependency ${dep}: ${error}`); + } +} \ No newline at end of file diff --git a/packages/controlflow/package.json b/packages/controlflow/package.json index 15161815..a2407e4b 100644 --- a/packages/controlflow/package.json +++ b/packages/controlflow/package.json @@ -1,12 +1,12 @@ { "name": "@nostrwatch/controlflow", - "version": "0.1.0", + "version": "0.2.0", "description": "Provides exports for application control flow", "main": "index.js", "type": "module", "license": "MIT", "dependencies": { - "bullmq": "4.14.2", + "bullmq": "^5.4.2", "dotenv": "16.3.1", "node-schedule": "2.1.1" }