diff --git a/services/watcher/handler.go b/services/watcher/handler.go index c897865..0ee2456 100644 --- a/services/watcher/handler.go +++ b/services/watcher/handler.go @@ -3,6 +3,7 @@ package watcher import ( "errors" "net/url" + "fmt" "github.com/gofiber/fiber/v2" ) @@ -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) } diff --git a/services/watcher/repository.go b/services/watcher/repository.go index baf1e93..2d80d76 100644 --- a/services/watcher/repository.go +++ b/services/watcher/repository.go @@ -3,6 +3,7 @@ package watcher import ( "context" "errors" + "fmt" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" @@ -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) diff --git a/services/watcher/service.go b/services/watcher/service.go index 2c7a801..c36beaa 100644 --- a/services/watcher/service.go +++ b/services/watcher/service.go @@ -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() } } @@ -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 @@ -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 @@ -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()