{"id":13601033,"url":"https://github.com/wang502/gores","last_synced_at":"2025-12-30T00:40:08.137Z","repository":{"id":57501173,"uuid":"77407774","full_name":"wang502/gores","owner":"wang502","description":":construction_worker: Redis-backed library for creating background jobs in Go. Placing jobs in multiple queues, and process them later asynchronously.","archived":false,"fork":false,"pushed_at":"2018-03-12T02:34:13.000Z","size":87,"stargazers_count":139,"open_issues_count":3,"forks_count":14,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-02-12T12:03:09.056Z","etag":null,"topics":["asynchronously","dispatch","enqueue","go","message-queue","microservice","redis","workers"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wang502.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-26T21:30:06.000Z","updated_at":"2024-09-08T06:05:59.000Z","dependencies_parsed_at":"2022-09-04T04:23:10.244Z","dependency_job_id":null,"html_url":"https://github.com/wang502/gores","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wang502%2Fgores","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wang502%2Fgores/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wang502%2Fgores/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wang502%2Fgores/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wang502","download_url":"https://codeload.github.com/wang502/gores/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248325002,"owners_count":21084848,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronously","dispatch","enqueue","go","message-queue","microservice","redis","workers"],"created_at":"2024-08-01T18:00:53.426Z","updated_at":"2025-12-30T00:40:08.090Z","avatar_url":"https://github.com/wang502.png","language":"Go","funding_links":[],"categories":["Go","workers"],"sub_categories":[],"readme":"# Gores [![Build Status](https://travis-ci.com/wang502/gores.svg?token=KeHkjMsksZ2RWDDg6h5k\u0026branch=master)](https://travis-ci.org/wang502/gores) [![Go Report Card](https://goreportcard.com/badge/github.com/wang502/gores)](https://goreportcard.com/report/github.com/wang502/gores)\nAn asynchronous job execution system based on Redis\n\n## Installation\nGet the package\n```\n$ go get github.com/wang502/gores/gores\n```\nImport the package\n```go\nimport \"github.com/wang502/gores/gores\"\n```\n\n## Usage\n### Start local Redis server\n```\n$ git clone git@github.com:antirez/redis.git\n$ cd redis\n$ ./src/redis-server\n```\n\n### Configuration\nAdd a config.json in your project folder\n```json\n{\n  \"RedisURL\": \"127.0.0.1:6379\",\n  \"RedisPassword\": \"mypassword\",\n  \"BlpopMaxBlockTime\" : 1,\n  \"MaxWorkers\": 2,\n  \"Queues\": [\"queue1\", \"queue2\"],\n  \"DispatcherTimeout\": 5,\n  \"WorkerTimeout\": 5\n}\n```\n- ***RedisURL***: Redis server address. If you run in a local Redis, the dafault host is ```127.0.0.1:6379```\n- ***RedisPassword***: Redis password. If the password is not set, then password can be any string.\n- ***BlpopMaxBlockTime***: Blocking time when calling BLPOP command in Redis.\n- ***MaxWorkers***: Maximum number of concurrent workers, each worker is a separate goroutine that execute specific task on the fetched item.\n- ***Queues***: Array of queue names on Redis message broker.\n- ***DispatcherTimeout***: Duration dispatcher will wait to dispatch new job before quitting.\n- ***WorkerTimeout***: Duration worker will wait to process new job before quitting.\n\nInitialize config\n```go\nconfigPath := flag.String(\"c\", \"config.json\", \"path to configuration file\")\nflag.Parse()\nconfig, err := gores.InitConfig(*configPath)\n```\n\n### Enqueue job to Redis queue\nA job is a Go map. It is required to have several keys:\n- ***Name***: name of the item to enqueue, items with different names are mapped to different tasks.\n- ***Queue***: name of the queue you want to put the item in.\n- ***Args***: the required arguments that you need in order for the workers to execute those tasks.\n- ***Enqueue_timestamp***: the Unix timestamp of when the item is enqueued.\n\n```go\ngores := gores.NewGores(config)\njob := map[string]interface{}{\n  \"Name\": \"Rectangle\",\n  \"Queue\": \"TestJob\",\n  \"Args\": map[string]interface{}{\n                \"Length\": 10,\n                \"Width\": 10,\n          },\n  \"Enqueue_timestamp\": time.Now().Unix(),\n}\n\nerr = gores.Enqueue(job)\nif err != nil {\n\tlog.Fatalf(\"ERROR Enqueue item to Gores\")\n}\n```\n\n```\n$ go run main.go -c ./config.json -o produce\n```\n\n### Define tasks\n```go\npackage tasks\n\n// task for item with 'Name' = 'Rectangle'\n// calculating the area of an rectangle by multiplying Length with Width\nfunc CalculateArea(args map[string]interface{}) error {\n    var err error\n\n    length := args[\"Length\"]\n    width := args[\"Width\"]\n    if length == nil || width == nil {\n        err = errors.New(\"Map has no required attributes\")\n        return err\n    }\n    \n    fmt.Printf(\"The area is %d\\n\", int(length.(float64)) * int(width.(float64)))\n    return err\n}\n```\n\n### Launch workers to consume items and execute tasks\n```go\ntasks := map[string]interface{}{\n              \"Item\": tasks.PrintItem,\n              \"Rectangle\": tasks.CalculateArea,\n         }\ngores.Launch(config, \u0026tasks)\n```\n\n```\n$ go run main.go -c ./config.json -o consume\n```\n\nThe output will be:\n```\nThe rectangle area is 100\n```\n\n### Info about processed/failed job\n```go\ngores := gores.NewGores(config)\nif gores == nil {\n    log.Fatalf(\"gores is nil\")\n}\n\ninfo, err := gores.Info()\nif err != nil {\n  log.Fatal(err)\n}\n\nfor k, v := range info {\n    switch v.(type) {\n    case string:\n      fmt.Printf(\"%s : %s\\n\", k, v)\n    case int:\n      fmt.Printf(\"%s : %d\\n\", k, v)\n    case int64:\n      fmt.Printf(\"%s : %d\\n\", k, v)\n    }\n}\n```\n\nThe output will be:\n```\nGores Info:\nqueues : 2\nworkers : 0\nfailed : 0\nhost : 127.0.0.1:6379\npending : 0\nprocessed : 1\n```\n\n## Contribution\nPlease feel free to suggest new features. Also open to pull request!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwang502%2Fgores","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwang502%2Fgores","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwang502%2Fgores/lists"}