Skip to content

Commit 2f35245

Browse files
committed
fix(timers): drop current response redis key on timer update
1 parent ace3c6c commit 2f35245

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

apps/timers/internal/activity/activity.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (c *Activity) SendMessage(ctx context.Context, timerId string) (
7979
return 0, nil
8080
}
8181

82-
currentResponse, err := c.redis.Get(ctx, "timers:current_response:"+timerId).Int()
82+
currentResponse, err := c.redis.Get(ctx, redis_keys.TimersCurrentResponse(timerId)).Int()
8383
if err != nil && !errors.Is(err, redis.Nil) {
8484
return currentResponse, err
8585
}
@@ -133,7 +133,7 @@ func (c *Activity) SendMessage(ctx context.Context, timerId string) (
133133
nextIndex = 0
134134
}
135135

136-
err = c.redis.Set(ctx, "timers:current_response:"+timerId, nextIndex, 24*time.Hour).Err()
136+
err = c.redis.Set(ctx, redis_keys.TimersCurrentResponse(timerId), nextIndex, 24*time.Hour).Err()
137137
if err != nil {
138138
return nextIndex, err
139139
}

apps/timers/internal/bus-listener/bus-listener.go

+8
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ package bus_listener
33
import (
44
"context"
55

6+
"github.com/redis/go-redis/v9"
67
"github.com/satont/twir/apps/timers/internal/workflow"
78
"github.com/satont/twir/libs/logger"
89
buscore "github.com/twirapp/twir/libs/bus-core"
910
"github.com/twirapp/twir/libs/bus-core/timers"
11+
"github.com/twirapp/twir/libs/redis_keys"
1012
"go.uber.org/fx"
1113
)
1214

1315
type server struct {
1416
workflow *workflow.Workflow
17+
redis *redis.Client
1518
}
1619

1720
type Opts struct {
@@ -21,11 +24,13 @@ type Opts struct {
2124
Logger logger.Logger
2225
Workflow *workflow.Workflow
2326
Bus *buscore.Bus
27+
Redis *redis.Client
2428
}
2529

2630
func New(opts Opts) error {
2731
s := &server{
2832
workflow: opts.Workflow,
33+
redis: opts.Redis,
2934
}
3035

3136
opts.Lc.Append(
@@ -49,6 +54,9 @@ func New(opts Opts) error {
4954
}
5055

5156
func (c *server) addTimerToQueue(ctx context.Context, t timers.AddOrRemoveTimerRequest) struct{} {
57+
c.redis.Del(ctx, redis_keys.TimersCurrentResponse(t.TimerID))
58+
59+
c.workflow.RemoveTimer(ctx, t.TimerID)
5260
c.workflow.AddTimer(ctx, t.TimerID)
5361

5462
return struct{}{}

libs/redis_keys/timers.go

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package redis_keys
2+
3+
func TimersCurrentResponse(timerId string) string {
4+
return "timers:current_response:" + timerId
5+
}

0 commit comments

Comments
 (0)