Skip to content

Commit

Permalink
Add DB Scan Duration Config
Browse files Browse the repository at this point in the history
  • Loading branch information
tung.tq committed Dec 19, 2023
1 parent bfafa75 commit d080872
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions config.tmp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ event_table_name: invalidate_events
offset_table_name: invalidate_offsets

event_retention_size: 10_000_000
db_scan_duration: 30s

notify_access_token: '' # pass to http header: X-Notify-Access-Token, not required if empty

Expand Down
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/url"
"strings"
"time"

"github.com/spf13/viper"
)
Expand All @@ -15,7 +16,8 @@ type Config struct {
EventTableName string `mapstructure:"event_table_name"`
OffsetTableName string `mapstructure:"offset_table_name"`

EventRetentionSize uint32 `mapstructure:"event_retention_size"`
EventRetentionSize uint32 `mapstructure:"event_retention_size"`
DBScanDuration time.Duration `mapstructure:"db_scan_duration"`

NotifyAccessToken string `mapstructure:"notify_access_token"`

Expand Down
1 change: 1 addition & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ event_table_name: invalidate_events
offset_table_name: invalidate_offsets

event_retention_size: 10_000_000
db_scan_duration: 30s

notify_access_token: '' # pass to http header: X-Notify-Access-Token, not required if empty

Expand Down
5 changes: 4 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"os/exec"
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -51,7 +52,9 @@ func TestLoadConfig(t *testing.T) {
OffsetTableName: "invalidate_offsets",

EventRetentionSize: 10_000_000,
NotifyAccessToken: "",
DBScanDuration: 30 * time.Second,

NotifyAccessToken: "",

DBType: DBTypeMySQL,
MySQL: MySQLConfig{
Expand Down
6 changes: 6 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ func Start() {
if conf.EventRetentionSize <= 10 {
panic("event_retention_size is too small")
}

fmt.Println("Event Retention Size:", humanize.FormatInteger("#,###.", int(conf.EventRetentionSize)))
fmt.Println("DB Scan Duration:", conf.DBScanDuration)

job := cacheinv.NewInvalidatorJob(
repo, client,
cacheinv.WithRunnerOptions(
eventx.WithDBProcessorRetryTimer(conf.DBScanDuration),
),
cacheinv.WithRetentionOptions(
eventx.WithMaxTotalEvents(uint64(conf.EventRetentionSize)),
eventx.WithDeleteBatchSize(32),
Expand Down

0 comments on commit d080872

Please sign in to comment.