Compare commits

..

No commits in common. "421527242e3873d05e55f8d1b2748faa40591ecb" and "90cdcf8745617929fe39b2f93b1890dcf572e353" have entirely different histories.

3 changed files with 14 additions and 49 deletions

View File

@ -1,5 +1,5 @@
import { NDKEvent, log } from '@nostr-dev-kit/ndk'
import { ndk } from '../../main.js'
import { NDKEvent } from '@nostr-dev-kit/ndk'
import { log, ndk } from '../../main.js'
export async function inProgress(event: NDKEvent): Promise<NDKEvent> {
log('marking job as in progress')
@ -11,13 +11,7 @@ export async function inProgress(event: NDKEvent): Promise<NDKEvent> {
})
reactEvent.tag(event, 'job')
await reactEvent.sign().catch((err) => {
throw `Event signing error: ${err}`
})
await reactEvent.publish().catch((err) => {
throw `Event publishing error: ${err}`
})
await reactEvent.sign()
await reactEvent.publish()
return reactEvent
}

View File

@ -28,9 +28,7 @@ export const ndk = new NDK({
],
signer: getSigner()
})
await ndk.connect(2000).catch((err) => log('NDK connection error: ', err))
await ndk.connect(2000)
log('connected')
const subs = ndk.subscribe(
@ -198,44 +196,25 @@ async function processJobEvent(event: NDKEvent, type: JobType): Promise<void> {
return promise
}
const logJobError = (job: JobType, err: any) =>
log(`Error thrown by ${job}: `, err)
const startProcessing = async () => {
log('startProcessing')
await inProgress(event).catch((err) => log('Processing event error: ', err))
await inProgress(event)
switch (type) {
case JobTypes.Summarize: {
output = await onNewSummarizationJob(event).catch((err) =>
logJobError(JobTypes.Summarize, err)
)
output = await onNewSummarizationJob(event)
break
}
case JobTypes.SpeechToText: {
output = await speechToTextJob(event).catch((err) =>
logJobError(JobTypes.SpeechToText, err)
)
output = await speechToTextJob(event)
break
}
case JobTypes.BlockChainBlockNumber: {
output = await blockChainBlockNumberJob(event).catch((err) =>
logJobError(JobTypes.BlockChainBlockNumber, err)
)
output = await blockChainBlockNumberJob(event)
break
}
case JobTypes.RelayInfo: {
output = await relayInfoJob(event).catch((err) =>
logJobError(JobTypes.RelayInfo, err)
)
output = await relayInfoJob(event)
break
}
}
@ -246,9 +225,7 @@ async function processJobEvent(event: NDKEvent, type: JobType): Promise<void> {
complete(event, missingAmount(), { output })
}
await validateJobRequest(event).catch((err) =>
log(`Job validation error: `, err)
)
await validateJobRequest(event)
if (jobAmount > paidAmount && waitForPaymentBeforeProcessing()) {
await reqPayment()

View File

@ -6,15 +6,9 @@ import { ndk } from '../main.js'
import { addAmount } from '../job-types/speech-to-text.js'
export async function validateJobRequest(event: NDKEvent): Promise<void> {
await validateExpiration(event).catch((err) => {
throw `Expiration error: ${err}`
})
await validateRequester(event).catch((err) => {
throw `Requester error: ${err}`
})
await validateNoRecentResults(event).catch((err) => {
throw `No recent results error: ${err}`
})
await validateExpiration(event)
await validateRequester(event)
await validateNoRecentResults(event)
}
export async function requirePayment(