Skip to content

kunal-saini/gobatch

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gobatch

Simple batch library for Golang.

How to Use

Install:

go get github.com/herryg91/gobatch

Example:

func fn1(workerID int, datas []interface{}) (err error) {
    //do something
    return
}

// every 100 datas or 15 second no activity, batch will be processed (fn1 will be run) with 2 worker
mBatch := gobatch.NewMemoryBatch(100, time.Second*15, fn1, 2)

mBatch.Insert(interface{}{})
mBatch.Insert(interface{}{})
mBatch.Insert(interface{}{})

Need additional param to DoFn? You can do something like this

type additionalParam struct {
	RedisPool *redis.Pool
}

func (p additionalParam) fn1(workerID int, datas []interface{}) (err error) {
	// do something log.Println(p)
	return
}

mBatch := gobatch.NewMemoryBatch(100, time.Second*15, additionalParam{pool}.fn1, 2)

Future Update:

  • Batch using Redis
  • Batch using File
  • Add / Decrease Worker on the fly

About

Batch Processing

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%