Skip to content

Commit

Permalink
Merge pull request #76 from planetary-social/add_last_id_suffix
Browse files Browse the repository at this point in the history
Add last_id env suffix
  • Loading branch information
dcadenas authored Oct 16, 2024
2 parents 40b40fa + 3877340 commit 21e7918
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion service/app/vanish_subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"os"
"time"

"github.com/boreq/errors"
"github.com/planetary-social/go-notification-service/internal/logging"
configadapters "github.com/planetary-social/go-notification-service/service/adapters/config"
"github.com/planetary-social/go-notification-service/service/domain"
"github.com/redis/go-redis/v9"
)
Expand Down Expand Up @@ -42,8 +44,14 @@ func NewVanishSubscriber(

// Processes messages from the vanish_requests stream and updates the last_id when done
func (f *VanishSubscriber) Run(ctx context.Context) error {
cfg, err := configadapters.NewEnvironmentConfigLoader().Load()
if err != nil {
return errors.Wrap(err, "error creating a config")
}

envSuffix := cfg.Environment().String()
streamName := "vanish_requests"
lastProcessedIDKey := "vanish_requests:notification_service:last_id"
lastProcessedIDKey := "vanish_requests:notification_service:last_id:" + envSuffix

lastProcessedID, err := f.rdb.Get(ctx, lastProcessedIDKey).Result()
if err == redis.Nil {
Expand Down
4 changes: 4 additions & 0 deletions service/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ type Environment struct {
s string
}

func (e Environment) String() string {
return e.s
}

var (
EnvironmentProduction = Environment{"production"}
EnvironmentDevelopment = Environment{"development"}
Expand Down

0 comments on commit 21e7918

Please sign in to comment.