Skip to content

Commit

Permalink
more error handling to attempt to catch 'EAI_AGAIN'
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Mar 19, 2024
1 parent d57072f commit 296f276
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 18 deletions.
26 changes: 24 additions & 2 deletions apps/nocapd/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,34 @@ const globalHandlers = ($daemon) => {

$daemon.$q.queue.on('error', async (err) => {
console.error('Queue Error: ', err);
gracefulShutdown(err)
if(err?.code === 'EAI_AGAIN' || JSON.stringify(err).includes('EAI_AGAIN')){
const code = err?.code? err.code: '[code undefined!]'
gracefulShutdown(code)
}
})

$daemon.$q.events.on('error', async (err) => {
console.error('QueueEvents Error: ', err);
if(err?.code === 'EAI_AGAIN' || JSON.stringify(err).includes('EAI_AGAIN')){
const code = err?.code? err.code: '[code undefined!]'
gracefulShutdown(code)
}
})

$daemon.$q.queue.on('ioredis:close', async (err) => {
console.error('Queue: ioredis:close: ', err);
gracefulShutdown(err)
if(err?.code === 'EAI_AGAIN' || JSON.stringify(err).includes('EAI_AGAIN')){
const code = err?.code? err.code: '[code undefined!]'
gracefulShutdown(code)
}
})

$daemon.$q.worker.on('error', async (err) => {
console.error('Worker Error: ', err);
if(err?.code === 'EAI_AGAIN' || JSON.stringify(err).includes('EAI_AGAIN')){
const code = err?.code? err.code: '[code undefined!]'
gracefulShutdown(code)
}
})
}

Expand Down
4 changes: 2 additions & 2 deletions packages/publisher/src/Publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ async function writeObjectToFile(obj) {

export class Publisher {

constructor(){
this.logger = new Logger('publisher[generic]')
constructor(key="generic"){
this.logger = new Logger(`publisher[${key}]`)
}

tpl(){
Expand Down
5 changes: 3 additions & 2 deletions packages/publisher/src/kinds/Kind0.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Publisher } from '../Publisher.js'

export class Kind0 extends Publisher {
constructor(){
super()
this.kind = 0
const KIND = 0
super(KIND)
this.kind = KIND
this.discoverable = { pubkey: true }
this.human_readable = false
this.machine_readable = true
Expand Down
6 changes: 3 additions & 3 deletions packages/publisher/src/kinds/Kind10002.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Publisher } from '../Publisher.js'

export class Kind10002 extends Publisher {
constructor(){
super()
this.kind = 10002
const KIND = 10002
super(KIND)
this.kind = KIND
this.discoverable = { pubkey: true }
this.human_readable = false
this.machine_readable = true
Expand All @@ -30,5 +31,4 @@ export class Kind10002 extends Publisher {
relays: event.tags.filter(tag => tag === 'r').map( tag => tag[1] )
}
}

}
6 changes: 3 additions & 3 deletions packages/publisher/src/kinds/Kind10166.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import ngeotags from 'nostr-geotags';
*/
export class Kind10166 extends Publisher {
constructor() {
super();
/** @type {number} The kind identifier. */
this.kind = 10166;
const KIND = 10166;
super(KIND);
this.kind = KIND;
}

/**
Expand Down
47 changes: 47 additions & 0 deletions packages/publisher/src/kinds/Kind1066.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,53 @@ import { Publisher } from '../Publisher.js'

export class Kind1066 extends Publisher {
constructor(){
const KIND = 1066
super()
this.kind = KIND
}
}import { Publisher } from '../Publisher.js'

export class Kind1066 extends Publisher {
constructor(){
const KIND = 1066
super(KIND)
this.kind = KIND
this.discoverable = { pubkey: true }
this.human_readable = false
this.machine_readable = true
}

generateEvent(data){
let tags = Kind1066.generateTags(data)
const event = {
...this.tpl(),
tags
}
return event
}

static generateTags(data){
if( !(relays instanceof Object) )
throw new Error("Kind1066: generateTags(data): data should be an object")
let tags = []

tags.push(['r', data.url])

const aTag = ['a', `30066:${data.pubkey}:${data.url}`]
if(data?.relayHint)
aTag.push(data.relayHint)
tags.push(aTag)

const deltas = data.deltas
.map( delta => [ ['D', delta.key], [delta.key, delta.value] ] )
.reduce( (acc, val) => [...acc, ...val], [] )

tags = [ ...tags, ...deltas ]
}

parse(event){
return {
relays: event.tags.filter( tag => tag === 'r' ).map( tag => tag[1] )
}
}
}
7 changes: 4 additions & 3 deletions packages/publisher/src/kinds/Kind30066.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import mapper from 'object-mapper'
import ngeohash from 'ngeohash'
import { ParseEvent } from '@nostrwatch/parse'
// import { ParseEvent } from '@nostrwatch/parse'

import { PublisherNocap } from '../Publisher.js'

export class Kind30066 extends PublisherNocap {
constructor(){
super()
this.kind = 30066
const KIND = 30066
super(KIND)
this.kind = KIND
this.discoverable = {tags: 'd'}
this.human_readable = true
this.machine_readable = true
Expand Down
7 changes: 4 additions & 3 deletions packages/publisher/src/kinds/Kind30166.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { PublisherNocap } from '../Publisher.js'

export class Kind30166 extends PublisherNocap {
constructor(){
super()
this.kind = 30166
const KIND =30166
super(KIND)
this.kind = KIND
this.discoverable = {tags: ['d', 'n', 'l', 'N', 's', 't', 'R']}
this.human_readable = false
this.machine_readable = true
Expand Down Expand Up @@ -65,7 +66,7 @@ export class Kind30166 extends PublisherNocap {
const current = data.ssl.data.valid_from < Date.now() && data.ssl.data.valid_to > Date.now()
tags.push(['R', current ? 'ssl' : '!ssl'])
}
else(protocol !== 'wss:') {
else if(protocol !== 'wss:') {
tags.push(['R', '!ssl'])
}

Expand Down

0 comments on commit 296f276

Please sign in to comment.