Skip to content

Commit

Permalink
containerization debugging #2
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Jan 23, 2024
1 parent 68d1365 commit 418f120
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion apps/trawler/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ RUN yarn install --network-timeout 1000000
# EXPOSE 3000

# Run the app when the container launches
CMD ["node", "src/index.js"]
CMD yarn launch
2 changes: 1 addition & 1 deletion apps/trawler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@nostr-fetch/adapter-nostr-tools": "0.13.1",
"@nostrwatch/controlflow": "^0.0.1",
"@nostrwatch/controlflow": "^0.0.2",
"@nostrwatch/logger": "^0.0.1",
"@nostrwatch/nocap": "^0.1.3",
"@nostrwatch/nwcache": "^0.0.1",
Expand Down
2 changes: 0 additions & 2 deletions apps/trawler/src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { configureQueues } from './queue.js'
import { bootstrap } from '@nostrwatch/seed'
import { chunkArray, msToCronTime } from '@nostrwatch/utils'

import { RedisConnectionDetails } from '@nostrwatch/utils'

const {trawlQueue, trawlWorker} = await configureQueues()
const logger = new Logger('daemon')
let busy = false
Expand Down
17 changes: 9 additions & 8 deletions apps/trawler/src/queue.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Worker } from 'bullmq';
import Redis from 'ioredis';

import { trawl } from './trawler.js';
import Logger from '@nostrwatch/logger'

import { TrawlQueue } from '@nostrwatch/controlflow'
import { TrawlQueue, BullMQ } from '@nostrwatch/controlflow'

const { Worker } = BullMQ

import { RedisConnectionDetails } from '@nostrwatch/utils'

export const configureQueues = async function(){

const connection = new Redis()
const connection = RedisConnectionDetails()

/**********
* Trawler
Expand All @@ -21,6 +22,7 @@ export const configureQueues = async function(){
const trawler = TrawlQueue({ removeOnComplete: { age: 30*60*1000 }, removeOnFail: { age: 30*60*1000 }, timeout: 1000*60*10 })

const trawlJobProgress = async ($job, progress) => {
console.log("progress")
if(!(progress instanceof Object)) return trawlLogger.warn(`Progress data is not an object, it's a ${typeof progress}`)
const { type, source } = progress
if(type === 'found'){
Expand Down Expand Up @@ -50,14 +52,13 @@ export const configureQueues = async function(){
trawlLogger.warn(`trawlJob ${$job.id} failed: ${err}`)
}

const trawlWorker = new Worker(trawler.$Queue.name, trawl, { concurrency: 1, maxStalledCount: 1 })
const trawlWorker = new Worker(trawler.$Queue.name, trawl, { concurrency: 1, maxStalledCount: 1, connection })
trawlWorker.on('completed', trawlJobCompleted)
trawlWorker.on('failed', trawlJobFailed)
trawlWorker.on('progress', trawlJobProgress)

return {
trawlQueue: trawler.$Queue,
trawlWorker,
connection
trawlWorker
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ class WebsocketAdapterDefault {
* @returns null
*/
handle_nostr_event(buffer){
const ev = JSON.parse(buffer.toString())
try{
const ev = JSON.parse(buffer.toString())
}
catch(e){
this.$.logger.error(`${this.$.url} responded with invalid JSON: ${e}`)
return this.$.on_error(e)
}
if(ev[0] === 'EVENT') {
if(this.$.subid('read') === ev[1])
this.$.on_event(ev[1], ev[2])
Expand Down
2 changes: 1 addition & 1 deletion packages/nocap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nostrwatch/nocap",
"version": "0.1.3",
"version": "0.1.4",
"main": "src/index.js",
"type": "module",
"license": "MIT",
Expand Down
12 changes: 6 additions & 6 deletions packages/nocap/src/classes/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,12 @@ export default class {
* @private
* @returns null
*/
handle_error(){
// this.unsubscribe()
// this.close()
this.websocket_hard_fail()
// this.finish(this.current, { [this.current]: false, duration: -1 }, this.promises.get(this.current).reject)
}
handle_error(){
// this.unsubscribe()
// this.close()
this.websocket_hard_fail()
// this.finish(this.current, { [this.current]: false, duration: -1 }, this.promises.get(this.current).reject)
}


/**
Expand Down

0 comments on commit 418f120

Please sign in to comment.