Skip to content

rfyiamcool/go-gearman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-gearman

The shardingkey is hashed to the same queue, each of which is bound to a worker.

Usage

init gearman

gm := gearman.NewGearman(workerNum, queueSize, SetIdleTimeout(1 * time.Minute), SetExceptionCall(func(error)))

start/stop

gm.Start()
defer gm.Stop()

Submit

gm.Submit(shardingKey, func() error)

Example

package main

import (
	"fmt"
	"sync"

	"github.com/rfyiamcool/go-gearman"
)

func main() {
	gm := gearman.NewGearman(10, 1000)
	gm.Start()
	defer gm.Stop()

	var (
		wg    = sync.WaitGroup{}
		count = 1000000 // 100w
	)

	wg.Add(count)

	cb := func() error {
		wg.Done()
		return nil
	}
	for i := 0; i < count; i++ {
		gm.Submit(fmt.Sprintf("id-%v", i), cb)
	}
	wg.Wait()
}

Packages

No packages published

Languages