Skip to content

Commit 274c904

Browse files
committed
Refactor the cron function in http sync
Signed-off-by: Zhiwei Liang <zhiwei.liang27@pm.me>
1 parent 9ee0c57 commit 274c904

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

core/pkg/sync/http/http_sync.go

+13-23
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,20 @@ func (hs *Sync) Sync(ctx context.Context, dataSync chan<- sync.DataSync) error {
8282

8383
if body == "" {
8484
hs.Logger.Debug("configuration deleted")
85-
} else {
86-
if hs.LastBodySHA == "" {
87-
hs.Logger.Debug("new configuration created")
88-
msg, err := hs.Fetch(ctx)
89-
if err != nil {
90-
hs.Logger.Error(fmt.Sprintf("error fetching: %s", err.Error()))
91-
} else {
92-
dataSync <- sync.DataSync{FlagData: msg, Source: hs.URI, Type: sync.ALL}
93-
}
94-
} else {
95-
currentSHA := hs.generateSha([]byte(body))
96-
if hs.LastBodySHA != currentSHA {
97-
hs.Logger.Debug("configuration modified")
98-
msg, err := hs.Fetch(ctx)
99-
if err != nil {
100-
hs.Logger.Error(fmt.Sprintf("error fetching: %s", err.Error()))
101-
} else {
102-
dataSync <- sync.DataSync{FlagData: msg, Source: hs.URI, Type: sync.ALL}
103-
}
104-
}
105-
106-
hs.LastBodySHA = currentSHA
107-
}
85+
return
10886
}
87+
88+
currentSHA := hs.generateSha([]byte(body))
89+
90+
if hs.LastBodySHA == "" {
91+
hs.Logger.Debug("new configuration created")
92+
dataSync <- sync.DataSync{FlagData: body, Source: hs.URI, Type: sync.ALL}
93+
} else if hs.LastBodySHA != currentSHA {
94+
hs.Logger.Debug("configuration modified")
95+
dataSync <- sync.DataSync{FlagData: body, Source: hs.URI, Type: sync.ALL}
96+
}
97+
98+
hs.LastBodySHA = currentSHA
10999
})
110100

111101
hs.Cron.Start()

0 commit comments

Comments
 (0)