Skip to content

Commit

Permalink
improve naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
thinhdanggroup committed Apr 1, 2020
1 parent cf4ddd1 commit aa269ca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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")
}
Expand Down
8 changes: 4 additions & 4 deletions executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -25,7 +25,7 @@ func TestPublishJobSuccess(t *testing.T) {

as = assert.New(t)

executor, err := NewExecutor(DefaultExecutorConfig())
executor, err := New(DefaultConfig())

as.Nil(err)

Expand All @@ -47,7 +47,7 @@ func TestPublishJobFail(t *testing.T) {

as = assert.New(t)

executor, err := NewExecutor(DefaultExecutorConfig())
executor, err := New(DefaultConfig())

as.Nil(err)

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit aa269ca

Please sign in to comment.