From aa269ca74f98cf571ad87ce7a8050aa4033cda43 Mon Sep 17 00:00:00 2001 From: thinhda Date: Wed, 1 Apr 2020 08:23:37 +0700 Subject: [PATCH] improve naming convention --- examples/example.go | 2 +- executor.go | 17 +++++++++-------- executor_test.go | 8 ++++---- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/examples/example.go b/examples/example.go index 47b5921..b10d34e 100644 --- a/examples/example.go +++ b/examples/example.go @@ -8,7 +8,7 @@ import ( ) func main() { - executor, err := executor.NewExecutor(executor.DefaultExecutorConfig()) + executor, err := executor.New(executor.DefaultConfig()) if err != nil { logrus.Error(err) diff --git a/executor.go b/executor.go index 67cc686..2e98cbb 100644 --- a/executor.go +++ b/executor.go @@ -24,27 +24,27 @@ type Job struct { Args []reflect.Value } -// ExecutorConfig is a config of executor. +// Config is a config of executor. // ReqPerSeconds is request per seconds. If it is 0, no limit for requests. // QueueSize is size of buffer. Executor use synchronize channel, publisher will waiting if channel is full. // NumWorkers is a number of goroutine. -type ExecutorConfig struct { +type Config struct { ReqPerSeconds int QueueSize int NumWorkers int } -// DefaultExecutorConfig is a default config -func DefaultExecutorConfig() ExecutorConfig { - return ExecutorConfig{ +// DefaultConfig is a default config +func DefaultConfig() Config { + return Config{ ReqPerSeconds: 0, QueueSize: 2 * runtime.NumCPU(), NumWorkers: runtime.NumCPU(), } } -// NewExecutor returns a Executors that will manage workers. -func NewExecutor(config ExecutorConfig) (*Executor, error) { +// New returns a Executors that will manage workers. +func New(config Config) (*Executor, error) { err := config.validate() if err != nil { @@ -104,6 +104,7 @@ func (pipeline *Executor) Publish(handler interface{}, inputArgs ...interface{}) return nil } +// PublishJob publish a provided job. func (pipeline *Executor) PublishJob(job *Job) { if pipeline.RateLimit != nil { pipeline.RateLimit.Take() @@ -165,7 +166,7 @@ func validateFunc(handler interface{}, nArgs int) (interface{}, error) { return f, nil } -func (p *ExecutorConfig) validate() error { +func (p *Config) validate() error { if p.ReqPerSeconds < 0 { return fmt.Errorf("%T must non negative", "ReqPerSeconds") } diff --git a/executor_test.go b/executor_test.go index 4e93881..5283c8e 100644 --- a/executor_test.go +++ b/executor_test.go @@ -10,7 +10,7 @@ import ( func TestValidateConfig(t *testing.T) { assert := assert.New(t) - executor, err := NewExecutor(ExecutorConfig{}) + executor, err := New(Config{}) assert.NotNil(err) assert.Nil(executor) @@ -25,7 +25,7 @@ func TestPublishJobSuccess(t *testing.T) { as = assert.New(t) - executor, err := NewExecutor(DefaultExecutorConfig()) + executor, err := New(DefaultConfig()) as.Nil(err) @@ -47,7 +47,7 @@ func TestPublishJobFail(t *testing.T) { as = assert.New(t) - executor, err := NewExecutor(DefaultExecutorConfig()) + executor, err := New(DefaultConfig()) as.Nil(err) @@ -77,7 +77,7 @@ func TestRateLimiter(t *testing.T) { as = assert.New(t) - executor, err := NewExecutor(ExecutorConfig{ + executor, err := New(Config{ ReqPerSeconds: 2, NumWorkers: 2, QueueSize: 10,