Skip to content

Commit

Permalink
improve control flow of daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Mar 17, 2024
1 parent 7686d92 commit 26829df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 1 addition & 2 deletions apps/nocapd/src/classes/Worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class NWWorker {
await this.addRelayJobs(relays)
else
this.setTimeout( this.populator.bind(this), this.interval)
await this.$.worker.resume()
return async () => await this.$.worker.resume()
}

async work(job){
Expand All @@ -95,7 +95,6 @@ export class NWWorker {
return { result }
}
catch(err) {
console.log(err)
failure(new Error(`Failure inside work() block: ${err}`))
return { result: { url: job.data.relay, open: { data: false }} }
}
Expand Down
11 changes: 7 additions & 4 deletions apps/nocapd/src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,28 @@ let config
let $q
let intervalPopulate
let intervalSyncRelays
let intervalBugCheck
let lastPopulate = 0

const populateQueue = async () => {
log.info(`drained: ${$q.queue.name}`)
await $q.checker.populator()
const resume = await $q.checker.populator()
await delay(2000)
await $q.checker.resetProgressCounts()
resume()
lastPopulate = Date.now()
}

const checkQueue = async () => {
const counts = await $q.checker.counts()
const enqueue = counts.prioritized + counts.active
if(enqueue > 0) return
log.info(`drained: ${$q.queue.name}`)
await populateQueue()
populateQueue()
}

const setIntervals = () => {
intervalSyncRelays = setInterval( syncRelaysIn, timestring(config?.nocapd?.seed?.options?.events?.interval, "ms") || timestring("1h", "ms"))
intervalPopulate = setInterval( checkQueue, timestring( "1m", "ms" ))
intervalPopulate = setInterval( checkQueue, timestring( config?.nocapd?.checks?.options?.interval, "ms" ))
}

const initWorker = async () => {
Expand Down

0 comments on commit 26829df

Please sign in to comment.