forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
- Loading branch information
1 parent
00ac76d
commit 3195f98
Showing
3 changed files
with
75 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package eventer | ||
|
||
import ( | ||
"github.com/spf13/pflag" | ||
|
||
"vitess.io/vitess/go/vt/log" | ||
topoevents "vitess.io/vitess/go/vt/topotools/events" | ||
) | ||
|
||
var ( | ||
eventers map[string]Eventer | ||
eventerName string = "log" | ||
) | ||
|
||
func RegisterFlags(fs *pflag.FlagSet) { | ||
fs.StringVar(&eventerName, "eventer", eventerName, "the eventer to be used to broadcast internal events") | ||
} | ||
|
||
type Source string | ||
|
||
var ( | ||
Vtctld Source = "vtctld" | ||
Vtorc Source = "vtorc" | ||
) | ||
|
||
type Eventer interface { | ||
EmergencyReparentShard(src Source, ev *topoevents.Reparent, err error) error | ||
PlannedReparentShard(src Source, ev *topoevents.Reparent, err error) error | ||
} | ||
|
||
func New() Eventer { | ||
if ev, ok := eventers[eventerName]; ok { | ||
return ev | ||
} | ||
return nil | ||
} | ||
|
||
type LogEventer struct{} | ||
|
||
func NewLogEventer() Eventer { return &LogEventer{} } | ||
|
||
func (le *LogEventer) EmergencyReparentShard(src Source, ev *topoevents.Reparent, err error) error { | ||
log.Infof("Received EmergencyReparentShardEvent: source=%s, err=%v, event=%v", src, err, ev) | ||
|
||
return nil | ||
} | ||
|
||
func (le *LogEventer) PlannedReparentShard(src Source, ev *topoevents.Reparent, err error) error { | ||
log.Infof("Received PlannedReparentShardEvent: source=%s, err=%v, event=%v", src, err, ev) | ||
|
||
return nil | ||
} | ||
|
||
func RegisterEventer(name string, e Eventer) { | ||
eventers[name] = e | ||
} | ||
|
||
func init() { | ||
eventers = make(map[string]Eventer, 0) | ||
RegisterEventer("log", NewLogEventer()) | ||
} |
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