Skip to content

Commit

Permalink
Merge pull request #35 from ambrosus/add-logs
Browse files Browse the repository at this point in the history
feat: add logs for debug && delete remove watcher meachanism on fcm e…
  • Loading branch information
serezhaolshan authored Nov 24, 2023
2 parents d067001 + 223c21c commit 45e3e66
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions services/watcher/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package watcher
import (
"errors"
"net/url"
"fmt"

"github.com/gofiber/fiber/v2"
)
Expand Down Expand Up @@ -49,6 +50,8 @@ func (h *Handler) GetWatcherHandler(c *fiber.Ctx) error {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": err.Error()})
}

fmt.Printf("GetWatcherHandler -> watcher: %+v\n", watcher)

return c.JSON(watcher)
}

Expand Down
3 changes: 3 additions & 0 deletions services/watcher/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package watcher
import (
"context"
"errors"
"fmt"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
Expand Down Expand Up @@ -82,6 +83,8 @@ func (r *repository) GetWatcherList(ctx context.Context, filters bson.M, page in
watchers = append(watchers, &watcher)
}

fmt.Printf("GetWatcherList -> watchers: %v\n", watchers)

// Check for any errors that occurred during iteration
if err := cur.Err(); err != nil {
r.logger.Errorf("cursor iteration error: %v", err)
Expand Down
13 changes: 9 additions & 4 deletions services/watcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,10 @@ func (s *service) TransactionWatch(ctx context.Context, address string, txHash s
if err != nil {
s.logger.Errorf("TransactionWatch cloudMessagingSvc.SendMessage error %v\n", err)
if err.Error() == "http error status: 404; reason: app instance has been unregistered; code: registration-token-not-registered; details: Requested entity was not found." {
s.mx.RLock()
watchers.Remove(watcher.PushToken)
s.mx.RUnlock()
return
// s.mx.RLock()
// watchers.Remove(watcher.PushToken) //TODO: check if this is needed
// s.mx.RUnlock()
}
}

Expand Down Expand Up @@ -470,7 +471,7 @@ func (s *service) GetWatcher(ctx context.Context, pushToken string) (*Watcher, e
return nil, errors.New("watcher not found")
}

fmt.Printf("!!GetWatcher -> watcher %v\n", watcher)
fmt.Printf("GetWatcher -> watcher %v\n", watcher)

s.mx.Lock()
s.cachedWatcher[encodePushToken] = watcher
Expand All @@ -495,6 +496,8 @@ func (s *service) CreateWatcher(ctx context.Context, pushToken string) error {
return errors.New("watcher for this address and token already exist")
}

fmt.Printf("GetWatcherHistoryPrices -> dbWatcher %v\n", dbWatcher)

watcher, err := NewWatcher(encodePushToken)
if err != nil {
return err
Expand All @@ -517,6 +520,8 @@ func (s *service) CreateWatcher(ctx context.Context, pushToken string) error {
return err
}

fmt.Printf("GetWatcherHistoryPrices -> watcher after repository create %v\n", dbWatcher)

s.mx.Lock()
s.cachedWatcher[watcher.PushToken] = watcher
s.mx.Unlock()
Expand Down

0 comments on commit 45e3e66

Please sign in to comment.