{"id":19484472,"url":"https://github.com/flowerinthenight/kettle","last_synced_at":"2025-04-25T16:33:39.815Z","repository":{"id":57499905,"uuid":"190121300","full_name":"flowerinthenight/kettle","owner":"flowerinthenight","description":"A simple library to share workloads to a group of workers with one leader at any time. Built on top of Redis.","archived":false,"fork":false,"pushed_at":"2023-08-22T04:30:44.000Z","size":4350,"stargazers_count":14,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T17:43:21.895Z","etag":null,"topics":["distributed-locking","go","golang","redis"],"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/flowerinthenight.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-04T03:18:58.000Z","updated_at":"2022-11-09T18:03:30.000Z","dependencies_parsed_at":"2024-06-19T00:16:05.214Z","dependency_job_id":"2838f058-9653-4292-b09f-cd0adc858e74","html_url":"https://github.com/flowerinthenight/kettle","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowerinthenight%2Fkettle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowerinthenight%2Fkettle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowerinthenight%2Fkettle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowerinthenight%2Fkettle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flowerinthenight","download_url":"https://codeload.github.com/flowerinthenight/kettle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224009478,"owners_count":17240568,"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":["distributed-locking","go","golang","redis"],"created_at":"2024-11-10T20:21:58.840Z","updated_at":"2025-04-25T16:33:39.802Z","avatar_url":"https://github.com/flowerinthenight.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![main](https://github.com/flowerinthenight/kettle/actions/workflows/main.yml/badge.svg)](https://github.com/flowerinthenight/kettle/actions/workflows/main.yml)\n[![Go Reference](https://pkg.go.dev/badge/github.com/flowerinthenight/kettle.svg)](https://pkg.go.dev/github.com/flowerinthenight/kettle)\n\n## Overview\n`kettle` is a simple library that abstracts the use of distributed locking to elect a master among group of workers at a specified time interval. The elected master will then call the \"master\" function. This library uses [Redis](https://redis.io/) as the default [distributed locker](https://redis.io/topics/distlock).\n\n## How it works\nAll workers that share the same name will attempt to grab a Redis lock to become the master. A provided master function will be executed by the node that successfully grabbed the lock. A single node works as well, in which case, that node will run both as master and a worker.\n\nThe main changes in v2.x.x is the use of context for termination and an optional 'done' channel for notification. It looks something like this:\n\n```go\nname := \"kettle-example\"\nk, _ := kettle.New(kettle.WithName(name), kettle.WithVerbose(true))\nin := kettle.StartInput{\n    // Our master callback function.\n    Master: func(v interface{}) error {\n        kt := v.(*kettle.Kettle)\n        log.Println(\"from master, name:\", kt.Name())\n        return nil\n    },\n    MasterCtx: k, // arbitrary data that is passed to master function\n}\n\nctx, cancel := context.WithCancel(context.TODO())\ndone := make(chan error, 1)\nerr = k.Start(ctx, \u0026in, done)\n_ = err\n\n// Simulate work\ntime.Sleep(time.Second * 5)\ncancel() // terminate\n\u003c-done   // wait\n```\n\n\nFor version 0.x.x, it looks something like this:\n\n```go\nname := \"kettle-example\"\nk, _ := kettle.New(kettle.WithName(name), kettle.WithVerbose(true))\nin := kettle.StartInput{\n    // Our master callback function.\n    Master: func(v interface{}) error {\n        kt := v.(*kettle.Kettle)\n        log.Println(\"from master, name:\", kt.Name())\n        return nil\n    },\n    MasterCtx: k, // arbitrary data that is passed to master function\n    Quit:      make(chan error),\n    Done:      make(chan error),\n}\n\nerr = k.Start(\u0026in)\n_ = err\n\n// Simulate work\ntime.Sleep(time.Second * 5)\nin.Quit \u003c- nil // terminate\n\u003c-in.Done      // wait\n```\n\n## Environment variables\n```bash\n# Required\nREDIS_HOST=1.2.3.4:6379\n\n# Optional\nREDIS_PASSWORD=***\nREDIS_TIMEOUT_SECONDS=5\n```\n\n## Example\nA simple example is provided [here](https://github.com/flowerinthenight/kettle/blob/master/examples/v2/simple/main.go) for reference. Try running it simultaneously on multiple nodes. For the version 0.x.x example, check it out [here](https://github.com/flowerinthenight/kettle/blob/master/examples/simple/main.go).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflowerinthenight%2Fkettle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflowerinthenight%2Fkettle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflowerinthenight%2Fkettle/lists"}