-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sotirios Mantziaris
authored
Jan 4, 2021
1 parent
33868aa
commit 7f03dbb
Showing
16 changed files
with
416 additions
and
207 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
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,54 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"sync" | ||
|
||
"github.com/beatlabs/harvester" | ||
"github.com/beatlabs/harvester/config" | ||
harvestersync "github.com/beatlabs/harvester/sync" | ||
) | ||
|
||
type cfg struct { | ||
IndexName harvestersync.String `seed:"customers-v1"` | ||
CacheRetention harvestersync.Int64 `seed:"43200" env:"ENV_CACHE_RETENTION_SECONDS"` | ||
LogLevel harvestersync.String `seed:"DEBUG" flag:"loglevel"` | ||
} | ||
|
||
func main() { | ||
ctx, cnl := context.WithCancel(context.Background()) | ||
defer cnl() | ||
|
||
err := os.Setenv("ENV_CACHE_RETENTION_SECONDS", "86400") | ||
if err != nil { | ||
log.Fatalf("failed to set env var: %v", err) | ||
} | ||
|
||
cfg := cfg{} | ||
chNotify := make(chan config.ChangeNotification) | ||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
|
||
go func() { | ||
for change := range chNotify { | ||
log.Printf("notification: " + change.String()) | ||
} | ||
wg.Done() | ||
}() | ||
|
||
h, err := harvester.New(&cfg).WithNotification(chNotify).Create() | ||
if err != nil { | ||
log.Fatalf("failed to create harvester: %v", err) | ||
} | ||
|
||
err = h.Harvest(ctx) | ||
if err != nil { | ||
log.Fatalf("failed to harvest configuration: %v", err) | ||
} | ||
|
||
log.Printf("Config : IndexName: %s, CacheRetention: %d, LogLevel: %s\n", cfg.IndexName.Get(), cfg.CacheRetention.Get(), cfg.LogLevel.Get()) | ||
close(chNotify) | ||
wg.Wait() | ||
} |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
module github.com/beatlabs/harvester | ||
|
||
go 1.13 | ||
go 1.15 | ||
|
||
require ( | ||
github.com/hashicorp/go-hclog v0.15.0 | ||
github.com/hashicorp/consul/api v1.8.1 | ||
github.com/hashicorp/go-hclog v0.15.0 | ||
github.com/stretchr/testify v1.6.1 | ||
) |
Oops, something went wrong.