You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
RedisURL: Redis server address. If you run in a local Redis, the dafault host is127.0.0.1:6379
RedisPassword: Redis password. If the password is not set, then password can be any string.
BlpopMaxBlockTime: Blocking time when calling BLPOP command in Redis.
MaxWorkers: Maximum number of concurrent workers, each worker is a separate goroutine that execute specific task on the fetched item.
Queues: Array of queue names on Redis message broker.
DispatcherTimeout: Duration dispatcher will wait to dispatch new job before quitting.
WorkerTimeout: Duration worker will wait to process new job before quitting.
Initialize config
configPath:=flag.String("c","config.json","path to configuration file")flag.Parse()config,err:=gores.InitConfig(*configPath)
Enqueue job to Redis queue
A job is a Go map. It is required to have several keys:
Name: name of the item to enqueue, items with different names are mapped to different tasks.
Queue: name of the queue you want to put the item in.
Args: the required arguments that you need in order for the workers to execute those tasks.
Enqueue_timestamp: the Unix timestamp of when the item is enqueued.
gores:=gores.NewGores(config)job:=map[string]interface{}{"Name":"Rectangle","Queue":"TestJob","Args":map[string]interface{}{"Length":10,"Width":10, },"Enqueue_timestamp":time.Now().Unix(),}err=gores.Enqueue(job)iferr!=nil {log.Fatalf("ERROR Enqueue item to Gores")}
$ go run main.go -c ./config.json -o produce
Define tasks
package tasks// task for item with 'Name' = 'Rectangle'// calculating the area of an rectangle by multiplying Length with WidthfuncCalculateArea(argsmap[string]interface{})error {varerrerrorlength:=args["Length"]width:=args["Width"]iflength==nil||width==nil {err=errors.New("Map has no required attributes")returnerr }fmt.Printf("The area is %d\n",int(length.(float64))*int(width.(float64)))returnerr}