Skip to content

Commit

Permalink
fix controlflow dep in nocapd
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Mar 16, 2024
1 parent 2866449 commit 8165349
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
25 changes: 13 additions & 12 deletions apps/nocapd/src/classes/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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){
Expand All @@ -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
Expand Down Expand Up @@ -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){
Expand All @@ -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}`)
}

Expand Down Expand Up @@ -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()
Expand Down
21 changes: 20 additions & 1 deletion apps/nocapd/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,23 @@ async function gracefulShutdown(signal) {
process.exit(9);
}

const $d = await run()
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}`);
}
}
4 changes: 2 additions & 2 deletions packages/controlflow/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
Expand Down

0 comments on commit 8165349

Please sign in to comment.