Skip to content

Commit 3eb835f

Browse files
committed
Specify auto expiration for redis backend
1 parent c47f5f3 commit 3eb835f

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

backend/redis/options.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package redis
2+
3+
import (
4+
"time"
5+
6+
"github.com/cschleiden/go-workflows/backend"
7+
)
8+
9+
type RedisOptions struct {
10+
backend.Options
11+
12+
BlockTimeout time.Duration
13+
14+
AutoExpiration time.Duration
15+
}
16+
17+
type RedisBackendOption func(*RedisOptions)
18+
19+
func WithBlockTimeout(timeout time.Duration) RedisBackendOption {
20+
return func(o *RedisOptions) {
21+
o.BlockTimeout = timeout
22+
}
23+
}
24+
25+
func WithBackendOptions(opts ...backend.BackendOption) RedisBackendOption {
26+
return func(o *RedisOptions) {
27+
for _, opt := range opts {
28+
opt(&o.Options)
29+
}
30+
}
31+
}
32+
33+
// WithAutoExpiration sets the duration after which finished runs will expire from the data store.
34+
// If set to 0 (default), runs will never expire and need to be manually removed.
35+
func WithAutoExpiration(expireFinishedRunsAfter time.Duration) RedisBackendOption {
36+
return func(o *RedisOptions) {
37+
o.AutoExpiration = expireFinishedRunsAfter
38+
}
39+
}

backend/redis/redis.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,6 @@ import (
1616
"go.opentelemetry.io/otel/trace"
1717
)
1818

19-
type RedisOptions struct {
20-
backend.Options
21-
22-
BlockTimeout time.Duration
23-
}
24-
25-
type RedisBackendOption func(*RedisOptions)
26-
27-
func WithBlockTimeout(timeout time.Duration) RedisBackendOption {
28-
return func(o *RedisOptions) {
29-
o.BlockTimeout = timeout
30-
}
31-
}
32-
33-
func WithBackendOptions(opts ...backend.BackendOption) RedisBackendOption {
34-
return func(o *RedisOptions) {
35-
for _, opt := range opts {
36-
opt(&o.Options)
37-
}
38-
}
39-
}
40-
4119
var _ backend.Backend = (*redisBackend)(nil)
4220

4321
func NewRedisBackend(client redis.UniversalClient, opts ...RedisBackendOption) (*redisBackend, error) {

0 commit comments

Comments
 (0)