Skip to content

[WIP] start rewriting to match server::starter 0.33#11

Open
lestrrat wants to merge 26 commits intomasterfrom
topic/compat-f10c90f
Open

[WIP] start rewriting to match server::starter 0.33#11
lestrrat wants to merge 26 commits intomasterfrom
topic/compat-f10c90f

Conversation

@lestrrat
Copy link
Copy Markdown
Collaborator

@lestrrat lestrrat commented Nov 27, 2016

after receiving #9, I looked at the original code for the first time in ages, and to my surprise, the original code had changed quite a bit. so here's me trying to match server::starter 0.32 0.33

fixes #10

@lestrrat lestrrat changed the title start rewriting to match server::starter 0.32 [WIP] start rewriting to match server::starter 0.32 Nov 27, 2016
Comment thread starter_test.go
"time"

"github.com/lestrrat/go-server-starter/internal/env"
tcputil "github.com/lestrrat/go-tcputil"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is no need to alias.

	"github.com/lestrrat/go-tcputil"

is equally good.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That's goimports doing its thing.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see.

@lestrrat lestrrat force-pushed the topic/compat-f10c90f branch from ab4bd4f to a7eea5f Compare February 26, 2017 07:52
@lestrrat lestrrat changed the title [WIP] start rewriting to match server::starter 0.32 [WIP] start rewriting to match server::starter 0.33 Feb 26, 2017
Copy link
Copy Markdown

@edvakf edvakf left a comment

Choose a reason for hiding this comment

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

Commented on internal/env

Comment thread internal/env/env.go Outdated
func NewLoader(environ ...string) *Loader {
if len(environ) == 0 {
environ = os.Environ()
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why don't we remove the arguments and change the test because it seems the only intended use case is without them?

Comment thread internal/env/env.go Outdated
return environ
}

func (l *Loader) Iterator(ctx context.Context, options ...Option) *Iterator {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What's the point of this iterator? Simply creating a slice of the environment variables would make the code much easier to follow.

Comment thread internal/env/env.go Outdated

func (l *Loader) Apply(octx context.Context, e Environment, options ...Option) error {
ctx, cancel := context.WithCancel(octx)
defer cancel()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Canceling after the iterator is finished looks meaningless.

Comment thread internal/env/interface.go Outdated
Value() interface{}
}

const LoadEnvdirKey = "LoadEnvdirKey"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If all we want is the LoadEnvdirKey flag, then having the interface and the struct feels too much of generalization. What do you think?

Copy link
Copy Markdown

@edvakf edvakf left a comment

Choose a reason for hiding this comment

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

Commented on monitor.go

Comment thread monitor.go
//
// users of this function can "wait" for the exit of a command
// by checking the done channel
func monitor(ctx context.Context, src chan *exec.Cmd, done chan *exec.Cmd) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The ctx is unused.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That was an omission lestrrat/go-server-starter@bb58920

Comment thread monitor.go
case chosen == len(workers)-1:
workers = workers[:chosen]
default:
workers = append(workers[:chosen], workers[chosen+1:]...)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The default works for all cases.

https://play.golang.org/p/Y4ywJVKGpp

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

What?
image
image

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oh wait, I got what you meant. Apologies.

Comment thread monitor.go
// users of this function can "wait" for the exit of a command
// by checking the done channel
func monitor(ctx context.Context, src chan *exec.Cmd, done chan *exec.Cmd) {
defer close(done)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why do you need this? This never occurs since the for loop never ends.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown

@edvakf edvakf left a comment

Choose a reason for hiding this comment

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

Commented on cli_test.go

Comment thread cli_test.go
func findInOptionList(t *testing.T, opts *options, name string, val interface{}) error {
for _, o := range makeOptionList(opts) {
switch o.Name() {
case name:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not just name := o.Name()?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

And when we add more options, we rewrite this? no.

Comment thread cli_test.go
}
for i := 1; i <= 2; i++ {
args := make([]string, len(paths))
for i, p := range paths {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Better to avoid using i. It would be an infinite loop if it was for i, p = range paths.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, the outer i controls how many arguments ParseArgs receives. I suppose there are better ways to write this, especially by removing i, but you completely miss the point of the code, and you are just looking at style.

Comment thread cli_test.go
}
for i := 1; i <= 2; i++ {
args := make([]string, len(ports))
for i, p := range ports {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, the outer i controls how many arguments ParseArgs receives. I suppose there are better ways to write this, especially by removing i, but you completely miss the point of the code, and you are just looking at style.

@lestrrat
Copy link
Copy Markdown
Collaborator Author

@edvakf Please ask about the context before making micro-style reviews. There are legitimate points in your review, true. But there's always a history behind code.

If this were coming from people whom I have worked with before I'd take this differently, but I don't know you, and you don't know the history behind it. I really don't feel good about random people that I don't know making random style comments without being asked to do so, or trying to understand me and the project history.

On the other hand, if you found bugs, please add tests. They are most appreciated.

@edvakf
Copy link
Copy Markdown

edvakf commented Feb 27, 2017

Apologies. My goal is to get this PR merged. Please ignore comments irrelevant to that direction.

@lestrrat
Copy link
Copy Markdown
Collaborator Author

@edvakf it would help immensely if you could try it out, and see if the features you care about are actually working, and report back with results!

@harukasan
Copy link
Copy Markdown
Contributor

harukasan commented Apr 14, 2017

日本語で失礼します…
まったく時間がとれておらずもうしわけありませんでした。少し前から、手元で試しているかんじでは問題ないように動いています。

ソースコードを読んでいてp5-server-starterとの差異を3つだけみつけたのでご参考までに。
lestrrat/go-server-starter@topic/compat-f10c90f...harukasan:compat

  • ALRMシグナルの扱い: perl版ではwaitのタイムアウトにalarmを使っているのでALRMをハンドリングする必要がありますが、go版では必要ないように思えます(あとperl版はただ無視していますがgo実装ではループを抜けていました)
  • AUTO_RESTART_INTERVALがセットされていないとき、perl版はsleepしません
  • 毎回pidをFindProcessしている実装が大丈夫かどうか気になっています。単にゴルーチンを起動してそのなかでWaitして待ち受けるほうが安全に思えますが、いかがでしょうか

@lestrrat
Copy link
Copy Markdown
Collaborator Author

おお。これテスト書いたほうがいいよねぇ(書きたくない…)
でもよさそうな感じなので、このブランチにPRくださいー。

FindProcessはその後でやるかな。というか、その辺りはcontext.Contextを使ったほうがよさそうなので、結構あちこちかわるのでは?と思いました。

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.

Indicate which version of p5-Server-Starter we based the go version on

3 participants