Skip to content
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

Remove section for executing resetDell periodically #101

Merged
merged 2 commits into from
Jan 11, 2024

Conversation

chez-shanpu
Copy link
Contributor

No description provided.

@chez-shanpu chez-shanpu self-assigned this Jan 9, 2024
pkg/monitor-hw/cmd/root.go Outdated Show resolved Hide resolved

env.Stop()
return env.Wait()
return resetDell(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor the caller of this facntion.
There is no longer a need to run this function as a goroutine.
https://github.com/cybozu-go/setup-hw/blob/v1.15.1/pkg/monitor-hw/cmd/root.go#L107-L109

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored it by deleting monitor functions. Also, I changed startExporter() to keep running without well.Wait().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check whether monitor-hw exits normally.
As far as I have confirmed, the following test programs did not terminate when receiving signals.
I think monitor-hw will be the same.

package main

import (
	"context"
	"io"
	"net/http"
	"time"

	"github.com/cybozu-go/log"
	"github.com/cybozu-go/well"
	"github.com/spf13/cobra"
)

func startExporter() error {
	well.Go(func(ctx context.Context) error {
		for {
			log.Info("Do collector.Update(ctx)", nil)
			select {
			case <-time.After(time.Second):
			case <-ctx.Done():
				return nil
			}
		}
	})

	mux := http.NewServeMux()
	mux.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
		io.WriteString(w, "Hello")
	})
	return http.ListenAndServe(":9105", mux)
}

var rootCmd = &cobra.Command{
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		cmd.SilenceUsage = true
		err := well.LogConfig{}.Apply()
		if err != nil {
			log.ErrorExit(err)
		}
	},

	RunE: func(cmd *cobra.Command, args []string) error {
		return startExporter()
	},
}

func main() {
	err := rootCmd.Execute()
	if err != nil {
		log.ErrorExit(err)
	}
}

Copy link
Contributor Author

@chez-shanpu chez-shanpu Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.
I rollbacked to use well.HTTPServer.ListenAndServe() and call well.Stop() and well.Wait at the parent function.

Signed-off-by: Tomoki Sugiura <tomoki-sugiura@cybozu.co.jp>
@chez-shanpu chez-shanpu force-pushed the remove-tick-reset branch 2 times, most recently from 0a2ee8c to 9ed1651 Compare January 10, 2024 01:52
Signed-off-by: Tomoki Sugiura <tomoki-sugiura@cybozu.co.jp>
Copy link
Contributor

@masa213f masa213f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chez-shanpu chez-shanpu merged commit f6b88d0 into main Jan 11, 2024
3 checks passed
@chez-shanpu chez-shanpu deleted the remove-tick-reset branch January 11, 2024 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants