2018-06-10 08:44:53 +02:00
|
|
|
package notifier
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jouir/pgterminate/base"
|
2018-06-24 17:49:48 +02:00
|
|
|
"github.com/jouir/pgterminate/log"
|
2018-06-10 08:44:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Console notifier structure
|
|
|
|
type Console struct {
|
2019-02-16 11:47:30 +01:00
|
|
|
format string
|
2018-07-08 23:48:48 +02:00
|
|
|
sessions chan *base.Session
|
2018-06-10 08:44:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewConsole creates a console notifier
|
2019-02-16 11:47:30 +01:00
|
|
|
func NewConsole(format string, sessions chan *base.Session) Notifier {
|
2018-06-10 08:44:53 +02:00
|
|
|
return &Console{
|
2019-02-16 11:47:30 +01:00
|
|
|
format: format,
|
2018-06-10 08:44:53 +02:00
|
|
|
sessions: sessions,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run starts console notifier
|
|
|
|
func (c *Console) Run() {
|
2018-06-24 17:49:48 +02:00
|
|
|
log.Info("Starting console notifier")
|
2018-06-10 08:44:53 +02:00
|
|
|
for session := range c.sessions {
|
2019-02-16 11:47:30 +01:00
|
|
|
log.Info(session.Format(c.format))
|
2018-06-10 08:44:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reload for handling SIGHUP signals
|
|
|
|
func (c *Console) Reload() {
|
2018-06-24 17:49:48 +02:00
|
|
|
log.Info("Reloading console notifier")
|
2018-06-10 08:44:53 +02:00
|
|
|
}
|