Skip to content
This repository was archived by the owner on Nov 5, 2024. It is now read-only.

Commit e61a40b

Browse files
committed
[cache]批量刷新缓存时,会将此动作同步到集群
1 parent b144672 commit e61a40b

14 files changed

Lines changed: 98 additions & 9 deletions

teacluster/action_fail.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ func (this *FailAction) Name() string {
1111
}
1212

1313
func (this *FailAction) TypeId() int8 {
14-
return 2
14+
return ActionCodeFail
1515
}

teacluster/action_notify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func (this *NotifyAction) Name() string {
1010
}
1111

1212
func (this *NotifyAction) TypeId() int8 {
13-
return 4
13+
return ActionCodeNotify
1414
}
1515

1616
func (this *NotifyAction) Execute() error {

teacluster/action_ping.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ func (this *PingAction) Name() string {
1212
}
1313

1414
func (this *PingAction) TypeId() int8 {
15-
return 7
15+
return ActionCodePing
1616
}

teacluster/action_pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ func (this *PullAction) Execute() error {
2020
}
2121

2222
func (this *PullAction) TypeId() int8 {
23-
return 6
23+
return ActionCodePull
2424
}

teacluster/action_push.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ func (this *PushAction) OnFail(fail *FailAction) error {
4444
}
4545

4646
func (this *PushAction) TypeId() int8 {
47-
return 5
47+
return ActionCodePush
4848
}

teacluster/action_register.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ func (this *RegisterAction) OnFail(fail *FailAction) error {
4040
}
4141

4242
func (this *RegisterAction) TypeId() int8 {
43-
return 3
43+
return ActionCodeRegister
4444
}

teacluster/action_run.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package teacluster
2+
3+
import (
4+
"github.com/TeaWeb/code/teacache"
5+
"github.com/TeaWeb/code/teaconfigs/shared"
6+
"github.com/iwind/TeaGo/logs"
7+
"github.com/iwind/TeaGo/maps"
8+
"github.com/iwind/TeaGo/types"
9+
)
10+
11+
type RunAction struct {
12+
Action
13+
14+
Cmd string
15+
Data maps.Map
16+
}
17+
18+
func (this *RunAction) Name() string {
19+
return "run"
20+
}
21+
22+
func (this *RunAction) Execute() error {
23+
switch this.Cmd {
24+
case "cache.refresh":
25+
this.runCacheRefresh()
26+
}
27+
return nil
28+
}
29+
30+
func (this *RunAction) TypeId() int8 {
31+
return ActionCodeRun
32+
}
33+
34+
// clean cache with prefixes
35+
func (this *RunAction) runCacheRefresh() {
36+
filename := this.Data.GetString("filename")
37+
policy := shared.NewCachePolicyFromFile(filename)
38+
if policy == nil {
39+
logs.Println("[cluster][cache.refresh]can not find policy with '" + filename + "'")
40+
return
41+
}
42+
43+
manager := teacache.FindCachePolicyManager(filename)
44+
if manager == nil {
45+
manager = teacache.NewManagerFromConfig(policy)
46+
}
47+
prefixes := this.Data.GetSlice("prefixes")
48+
prefixStrings := []string{}
49+
for _, prefix := range prefixes {
50+
prefixStrings = append(prefixStrings, types.String(prefix))
51+
}
52+
_, err := manager.DeletePrefixes(prefixStrings)
53+
if err != nil {
54+
logs.Println("[cluster][cache.refresh]delete prefixes")
55+
return
56+
}
57+
}

teacluster/action_success.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ func (this *SuccessAction) Name() string {
1414
}
1515

1616
func (this *SuccessAction) TypeId() int8 {
17-
return 1
17+
return ActionCodeSuccess
1818
}

teacluster/action_sum.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ func (this *SumAction) OnFail(fail *FailAction) error {
6363
}
6464

6565
func (this *SumAction) TypeId() int8 {
66-
return 9
66+
return ActionCodeSum
6767
}

teacluster/action_sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ func (this *SyncAction) Execute() error {
6666
}
6767

6868
func (this *SyncAction) TypeId() int8 {
69-
return 8
69+
return ActionCodeSync
7070
}

0 commit comments

Comments
 (0)