Skip to content

Commit

Permalink
attempt to fix hanging worker by thrownig error
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Sep 18, 2024
1 parent ba0a112 commit 10d9cf4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
13 changes: 9 additions & 4 deletions apps/nocapd/src/classes/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import nocapAdapters from "@nostrwatch/nocap-every-adapter-default"

import { relayHostnameDedup } from '../hostnames.js';

const TIMEOUT = 2*60*1000

let errors = 0

export class NWWorker {
Expand Down Expand Up @@ -49,13 +51,14 @@ export class NWWorker {
timeout: this.timeout,
checked_by: this.pubkey
}

this.jobOpts = {
attempts: 1,
timeout: 1000*30,
removeOnComplete: true,
removeOnComplete: {
age: timestring(this.config.nocapd.checks.options.expires, 's')
},
removeOnFail: {
age: timestring('2m', 's')
age: timestring('10m', 's')
}
}

Expand Down Expand Up @@ -133,10 +136,12 @@ export class NWWorker {
const failure = (err) => { this.log.err(`Could not run ${this.pubkey} check for ${job.data.relay}: ${err.message}`) }
let result = {}
try {
const timeout = this.setTimeout( () => { throw new Error(`Job Timedout: ${job.id} after ${TIMEOUT/1000}s`), TIMEOUT })
const { relay:url } = job.data
const nocap = new Nocap(url, {...this.nocapOpts, logLevel: 'debug'})
await nocap.useAdapters([...Object.values(nocapAdapters)])
result = await nocap.check(this.opts.checks.enabled).catch(failure)
clearTimeout(timeout)
return { result }
}
catch(err) {
Expand Down
17 changes: 9 additions & 8 deletions internal/seed/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Logger from "@nostrwatch/logger"
import { fetch } from "cross-fetch"
import config from "./config.js"

let cache

const DEFAULT_RELAYS = [ "wss://relay.nostr.watch", "wss://history.nostr.watch", "wss://relaypag.es" ]

const STATIC_SEED_FILE = new URL('seed.yaml', import.meta.url);
Expand Down Expand Up @@ -99,12 +101,15 @@ export const relaysFromCache = async (opts) => {
const { openDb, DbWrapper, initializeDb } = await import("@nostrwatch/nwcache")

let result
let cache
cache

try {
let lmdb = openDb(cacheOpts.path, { maxDbs: 10 })
cache = new DbWrapper(lmdb)
cache = initializeDb(cache)
let lmdb
if(!cache) {
lmdb = openDb(cacheOpts.path, { maxDbs: 10 })
cache = new DbWrapper(lmdb)
cache = initializeDb(cache)
}

if(cacheOpts?.onlineOnly) {
result = await cache.relay.get.online('url')
Expand All @@ -114,15 +119,11 @@ export const relaysFromCache = async (opts) => {
}

result = result.map( relay => relay.url )

cache.$.close()
}
catch(e){
logger.err(e)
}

cache = null

return [ result, Date.now() ]
}

Expand Down

0 comments on commit 10d9cf4

Please sign in to comment.