mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-20 18:18:08 +02:00
zero: group funcs that need run within a lease
This commit is contained in:
parent
faa2a8652b
commit
3ebb096dfc
6 changed files with 135 additions and 60 deletions
37
internal/zero/leaser/monitor.go
Normal file
37
internal/zero/leaser/monitor.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
package leaser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||
)
|
||||
|
||||
const typeStr = "pomerium.io/zero/leaser"
|
||||
|
||||
// databrokerChangeMonitor runs infinite sync loop to see if there is any change in databroker
|
||||
// it doesn't really syncs anything, just checks if the underlying databroker has changed
|
||||
func (c *service) databrokerChangeMonitor(ctx context.Context) error {
|
||||
_, recordVersion, serverVersion, err := databroker.InitialSync(ctx, c.GetDataBrokerServiceClient(), &databroker.SyncLatestRequest{
|
||||
Type: typeStr,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("error during initial sync: %w", err)
|
||||
}
|
||||
|
||||
stream, err := c.GetDataBrokerServiceClient().Sync(ctx, &databroker.SyncRequest{
|
||||
Type: typeStr,
|
||||
ServerVersion: serverVersion,
|
||||
RecordVersion: recordVersion,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("error calling sync: %w", err)
|
||||
}
|
||||
|
||||
for {
|
||||
_, err := stream.Recv()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error receiving record: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue