-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notification Addition #73
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a77cafd
Notification addition
mantzas 505fcd8
Notification addition
mantzas e14bc6b
Notification addition
mantzas cb488aa
Notification addition
mantzas cad4f5f
Notification addition
mantzas 678f000
Notification addition
mantzas 2cb748a
Notification addition
mantzas 73861e1
Notification addition
mantzas 6793ed9
Notification addition
mantzas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,53 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"sync" | ||
|
||
"github.com/beatlabs/harvester" | ||
harvestersync "github.com/beatlabs/harvester/sync" | ||
) | ||
|
||
type config 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 := config{} | ||
chNotify := make(chan string) | ||
wg := sync.WaitGroup{} | ||
wg.Add(1) | ||
|
||
go func() { | ||
for change := range chNotify { | ||
log.Printf("notification: " + change) | ||
} | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the ability to track changes in configuration is awesome, but I think sending just a string doesn't give too much value.
It would be better to send a notification
struct
with more information like the previous and next values along with the field (at least its name) so that some kind of calculation can be done from the user.For example if there is a bigger change than
x%
or maybe send these values to another service (ex. auditing, event message etc.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. On it.