diff --git a/README.md b/README.md index a340cb6..705ada8 100644 --- a/README.md +++ b/README.md @@ -282,6 +282,9 @@ flowchart TB 3. **Tag the Image:** Tag the image with the `stable` tag as described in the [GitHub documentation](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry). + ``` + docker tag ghcr.io/planetary-social/nos-notification-service-go:latest ghcr.io/planetary-social/nos-notification-service-go:stable && docker push ghcr.io/planetary-social/nos-notification-service-go:stable + ``` 4. **Trigger the Image Update Process:** The image update process checks for new tags every 3 minutes. Therefore, you should see the new image deployed in approximately 5 minutes. diff --git a/service/adapters/gcp/gcp_follow_change_subscriber.go b/service/adapters/gcp/gcp_follow_change_subscriber.go index 898c78f..0f42335 100644 --- a/service/adapters/gcp/gcp_follow_change_subscriber.go +++ b/service/adapters/gcp/gcp_follow_change_subscriber.go @@ -47,17 +47,15 @@ func (p *GCPFollowChangeSubscriber) Subscribe(ctx context.Context) (<-chan *doma ch := make(chan *domain.FollowChange) - defer func() { - close(ch) - p.subscriber.Close() - }() - go func() { - var payload domain.FollowChange + defer close(ch) + defer p.subscriber.Close() + for message := range subChan { // We never retry messages so we can ACK immediately. message.Ack() + var payload domain.FollowChange if err := json.Unmarshal(message.Payload, &payload); err != nil { p.logger.Error("error unmarshaling follow change payload", err, watermill.LogFields{"payload": string(message.Payload)}) continue diff --git a/service/app/follow_change_puller.go b/service/app/follow_change_puller.go index 6e43e01..93ece7c 100644 --- a/service/app/follow_change_puller.go +++ b/service/app/follow_change_puller.go @@ -36,7 +36,8 @@ func (f *FollowChangePuller) Run(ctx context.Context) error { } for followChange := range ch { - f.logger.Debug().WithField("followChange", followChange).Message("received follow change") + f.logger.Debug().Message(followChange.String()) + f.counter += 1 } diff --git a/service/domain/follow_change.go b/service/domain/follow_change.go index bc2ab22..5fc38b4 100644 --- a/service/domain/follow_change.go +++ b/service/domain/follow_change.go @@ -1,15 +1,22 @@ package domain +import ( + "encoding/json" + "errors" + "fmt" + "time" +) + type FollowChange struct { ChangeType string `json:"changeType"` - At uint `json:"at"` + At time.Time `json:"at"` Follower PublicKey `json:"follower"` Followee PublicKey `json:"followee"` FriendlyFollowee string `json:"friendlyFollowee"` FriendlyFollower string `json:"friendlyFollower"` } -func NewFollowChange(changeType string, follower PublicKey, friendlyFollower string, followee PublicKey, friendlyFollowee string, at uint) FollowChange { +func NewFollowChange(changeType string, follower PublicKey, friendlyFollower string, followee PublicKey, friendlyFollowee string, at time.Time) FollowChange { return FollowChange{ ChangeType: changeType, Follower: follower, @@ -19,3 +26,44 @@ func NewFollowChange(changeType string, follower PublicKey, friendlyFollower str At: at, } } + +func (f *FollowChange) UnmarshalJSON(data []byte) error { + var temp struct { + ChangeType string `json:"changeType"` + At int64 `json:"at"` + Follower string `json:"follower"` + Followee string `json:"followee"` + FriendlyFollowee string `json:"friendlyFollowee"` + FriendlyFollower string `json:"friendlyFollower"` + } + + if err := json.Unmarshal(data, &temp); err != nil { + return err + } + + f.ChangeType = temp.ChangeType + f.At = time.Unix(temp.At, 0) + f.FriendlyFollowee = temp.FriendlyFollowee + f.FriendlyFollower = temp.FriendlyFollower + + var err error + f.Follower, err = NewPublicKeyFromHex(temp.Follower) + if err != nil { + return errors.New("invalid hex for follower: " + err.Error()) + } + + f.Followee, err = NewPublicKeyFromHex(temp.Followee) + if err != nil { + return errors.New("invalid hex for followee: " + err.Error()) + } + + return nil +} + +func (f FollowChange) String() string { + if f.ChangeType == "unfollowed" { + return fmt.Sprintf("New unfollow: %s(%s) --x--> %s(%s)", f.FriendlyFollower, f.Follower.s, f.FriendlyFollowee, f.Followee.s) + } + + return fmt.Sprintf("New follow: %s(%s) -----> %s(%s)", f.FriendlyFollower, f.Follower.s, f.FriendlyFollowee, f.Followee.s) +}