-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added changes for using queue only if poller is not enabled in config * Added changes for poller config in treatment service * Added changes for poller in treatment service * Added changes for poller in treatment service * Added changes for poller in treatment service * Reverted poller changes for management-service * Fixed treatment service config test case * Refactored poller * Fixed poller condition * Refactored poller * Removed unused struct * Integrated PR review comments * Integrated PR review comments * Integrated PR review comments * Added sample poller config * Integrated PR review comments * Integrated PR review comments * Integrated PR review comments * Integrated PR review comments --------- Co-authored-by: Anirudh Rautela <[email protected]>
- Loading branch information
1 parent
d328d9e
commit 397e59b
Showing
9 changed files
with
112 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,7 @@ SegmenterConfig: | |
S2_IDs: | ||
MinS2CellLevel: 10 | ||
MaxS2CellLevel: 14 | ||
|
||
PollerConfig: | ||
Enabled: true | ||
PollInterval: 10s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package server | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
"github.com/caraml-dev/xp/treatment-service/config" | ||
"github.com/caraml-dev/xp/treatment-service/models" | ||
) | ||
|
||
type Poller struct { | ||
pollerConfig config.ManagementServicePollerConfig | ||
localStorage *models.LocalStorage | ||
stopChannel chan struct{} | ||
} | ||
|
||
// NewPoller creates a new Poller instance with the given configuration and local storage. | ||
// pollerConfig: configuration for the poller | ||
// localStorage: local storage to be used by the poller | ||
func NewPoller(pollerConfig config.ManagementServicePollerConfig, localStorage *models.LocalStorage) *Poller { | ||
return &Poller{ | ||
pollerConfig: pollerConfig, | ||
localStorage: localStorage, | ||
stopChannel: make(chan struct{}), | ||
} | ||
} | ||
|
||
func (p *Poller) Start() { | ||
ticker := time.NewTicker(p.pollerConfig.PollInterval) | ||
go func() { | ||
for { | ||
select { | ||
case <-ticker.C: | ||
err := p.Refresh() | ||
log.Printf("Polling at %v with interval %v", time.Now(), p.pollerConfig.PollInterval) | ||
if err != nil { | ||
log.Printf("Error updating local storage: %v", err) | ||
continue | ||
} | ||
case <-p.stopChannel: | ||
ticker.Stop() | ||
return | ||
} | ||
} | ||
}() | ||
} | ||
|
||
func (p *Poller) Stop() { | ||
close(p.stopChannel) | ||
} | ||
|
||
func (p *Poller) Refresh() error { | ||
err := p.localStorage.Init() | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters