Skip to content

Commit

Permalink
Change method names and some log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Oct 10, 2023
1 parent da2497c commit aab13a9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/channel/email/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (ch *Email) SendNotification(req *plugin.NotificationRequest) error {
func (ch *Email) SetConfig(jsonStr json.RawMessage) error {
err := json.Unmarshal(jsonStr, ch)
if err != nil {
return fmt.Errorf("failed to load config:%s %w", jsonStr, err)
return fmt.Errorf("failed to load config: %s %w", jsonStr, err)
}

if ch.Host == "" {
Expand Down
14 changes: 7 additions & 7 deletions internal/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Channel struct {
mu sync.Mutex
}

func (c *Channel) StartPlugin(pluginDir string) error {
func (c *Channel) Start(pluginDir string) error {
c.mu.Lock()
defer c.mu.Unlock()

Expand Down Expand Up @@ -79,12 +79,12 @@ func (c *Channel) StartPlugin(pluginDir string) error {
return nil
}

func (c *Channel) ResetPlugin() {
func (c *Channel) Stop() {
c.mu.Lock()
defer c.mu.Unlock()

if c.cmd == nil {
c.Logger.Debug("channel has already been reset")
c.Logger.Debug("channel plugin has already been stopped")
return
}

Expand All @@ -93,7 +93,7 @@ func (c *Channel) ResetPlugin() {
c.cmd = nil
c.rpc = nil

c.Logger.Debug("reset channel successfully")
c.Logger.Debug("Stopped channel plugin successfully")
}

func forwardLogs(errPipe io.Reader, logger *zap.SugaredLogger) {
Expand All @@ -114,15 +114,15 @@ func forwardLogs(errPipe io.Reader, logger *zap.SugaredLogger) {

// run as go routine to terminate given channel
func (c *Channel) terminate(cmd *exec.Cmd, rpc *rpc.RPC) {
c.Logger.Debug("terminating channel")
c.Logger.Debug("terminating channel plugin")
_ = rpc.Close()

timer := time.AfterFunc(5*time.Second, func() {
c.Logger.Debug("killing the channel")
c.Logger.Debug("killing the channel plugin")
_ = cmd.Process.Kill()
})

_ = cmd.Wait()
timer.Stop()
c.Logger.Debug("Channel terminated successfully")
c.Logger.Debug("Channel plugin terminated successfully")
}
2 changes: 1 addition & 1 deletion internal/channel/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (c *Channel) rpcCall(method string, params json.RawMessage) (json.RawMessag

var rpcErr *rpc.Error
if errors.As(err, &rpcErr) {
c.ResetPlugin()
c.Stop()
}

return result, err
Expand Down
4 changes: 2 additions & 2 deletions internal/config/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ func (r *RuntimeConfig) applyPendingChannels() {
currentChannel.Name = pendingChannel.Name
currentChannel.Config = pendingChannel.Config

currentChannel.Logger.Info("Resetting the channel because the config has been changed")
currentChannel.ResetPlugin()
currentChannel.Logger.Info("Stopping the channel plugin because the config has been changed")
currentChannel.Stop()
}
} else {
r.Channels[typ] = pendingChannel
Expand Down
2 changes: 1 addition & 1 deletion internal/incident/incident.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func (i *Incident) notifyContacts(ctx context.Context, tx *sqlx.Tx, ev *event.Ev
continue
}

err = ch.StartPlugin(i.configFile.ChannelPluginDir)
err = ch.Start(i.configFile.ChannelPluginDir)
if err != nil {
i.logger.Errorw("Could not initialize channel", zap.String("type", chType), zap.Error(err))
continue
Expand Down

0 comments on commit aab13a9

Please sign in to comment.