Skip to content

Commit

Permalink
new: add lazy load rule sets
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com committed Feb 20, 2024
1 parent 362291c commit bc0f284
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions route/rule_set_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ func (s *RemoteRuleSet) StartContext(ctx context.Context, startContext adapter.R
s.lastEtag = savedSet.LastEtag
}
}
s.updateTicker = time.NewTicker(s.updateInterval)
if s.lastUpdated.IsZero() {
err := s.fetchOnce(ctx, startContext)
if err != nil {
return E.Cause(err, "initial rule-set: ", s.options.Tag)
// return E.Cause(err, "initial rule-set: ", s.options.Tag)
s.logger.Error(E.Cause(err, "initial rule-set: ", s.options.Tag))
s.updateTicker = time.NewTicker(10 * time.Second)
}
}
s.updateTicker = time.NewTicker(s.updateInterval)

go s.loopUpdate()
return nil
}
Expand Down Expand Up @@ -159,6 +162,7 @@ func (s *RemoteRuleSet) loopUpdate() {
err := s.fetchOnce(s.ctx, nil)
if err != nil {
s.logger.Error("fetch rule-set ", s.options.Tag, ": ", err)

}
}
for {
Expand All @@ -171,6 +175,8 @@ func (s *RemoteRuleSet) loopUpdate() {
err := s.fetchOnce(s.ctx, nil)
if err != nil {
s.logger.Error("fetch rule-set ", s.options.Tag, ": ", err)
} else {
s.updateTicker = time.NewTicker(s.updateInterval)
}
}
}
Expand Down

0 comments on commit bc0f284

Please sign in to comment.