Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #167 from getAlby/task-refactoring-1
Browse files Browse the repository at this point in the history
fix: request event state after publishing response
  • Loading branch information
rolznz authored Mar 28, 2024
2 parents c1ef741 + 6de171b commit db1ee69
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,31 +531,24 @@ func (svc *Service) HandleEvent(ctx context.Context, sub *nostr.Subscription, ev
"requestEventNostrId": event.ID,
"eventKind": event.Kind,
}).Errorf("Failed to create response: %v", err)

requestEvent.State = REQUEST_EVENT_STATE_HANDLER_ERROR
err = svc.db.Save(&requestEvent).Error
} else {
err = svc.PublishEvent(ctx, sub, &requestEvent, resp, &app, ss)
if err != nil {
svc.Logger.WithFields(logrus.Fields{
"nostrPubkey": event.PubKey,
}).Errorf("Failed to save state to nostr event: %v", err)
"requestEventNostrId": event.ID,
"eventKind": event.Kind,
}).Errorf("Failed to publish event: %v", err)
requestEvent.State = REQUEST_EVENT_STATE_HANDLER_ERROR
} else {
requestEvent.State = REQUEST_EVENT_STATE_HANDLER_EXECUTED
}
return
}
err = svc.PublishEvent(ctx, sub, &requestEvent, resp, &app, ss)

err = svc.db.Save(&requestEvent).Error
if err != nil {
svc.Logger.WithFields(logrus.Fields{
"requestEventNostrId": event.ID,
"eventKind": event.Kind,
}).Errorf("Failed to publish event: %v", err)

requestEvent.State = REQUEST_EVENT_STATE_HANDLER_ERROR
err = svc.db.Save(&requestEvent).Error
if err != nil {
svc.Logger.WithFields(logrus.Fields{
"nostrPubkey": event.PubKey,
}).Errorf("Failed to save state to nostr event: %v", err)
}
"nostrPubkey": event.PubKey,
}).Errorf("Failed to save state to nostr event: %v", err)
}
}

Expand All @@ -581,14 +574,6 @@ func (svc *Service) HandleEvent(ctx context.Context, sub *nostr.Subscription, ev
default:
svc.handleUnknownMethod(ctx, nip47Request, publishResponse)
}

requestEvent.State = REQUEST_EVENT_STATE_HANDLER_EXECUTED
err = svc.db.Save(&requestEvent).Error
if err != nil {
svc.Logger.WithFields(logrus.Fields{
"nostrPubkey": event.PubKey,
}).Errorf("Failed to save state to nostr event: %v", err)
}
}

func (svc *Service) handleUnknownMethod(ctx context.Context, nip47Request *Nip47Request, publishResponse func(*Nip47Response, nostr.Tags)) {
Expand Down

0 comments on commit db1ee69

Please sign in to comment.