{"id":25911404,"url":"https://github.com/copyleftdev/randexc","last_synced_at":"2025-10-27T19:09:02.078Z","repository":{"id":254684740,"uuid":"847256003","full_name":"copyleftdev/randexc","owner":"copyleftdev","description":"A Go library for executing actions at random times within specified durations. Perfect for load testing, simulating real-world events, and implementing jittered backoff strategies.","archived":false,"fork":false,"pushed_at":"2024-08-25T10:01:33.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-26T11:14:18.086Z","etag":null,"topics":["backoff","execution","go","jitter","random","testing"],"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/copyleftdev.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":"2024-08-25T09:50:52.000Z","updated_at":"2024-08-25T10:01:36.000Z","dependencies_parsed_at":"2024-08-25T11:03:43.472Z","dependency_job_id":null,"html_url":"https://github.com/copyleftdev/randexc","commit_stats":null,"previous_names":["copyleftdev/randexc"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copyleftdev%2Frandexc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copyleftdev%2Frandexc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copyleftdev%2Frandexc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/copyleftdev%2Frandexc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/copyleftdev","download_url":"https://codeload.github.com/copyleftdev/randexc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241637275,"owners_count":19994946,"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":["backoff","execution","go","jitter","random","testing"],"created_at":"2025-03-03T09:17:25.508Z","updated_at":"2025-10-27T19:09:02.004Z","avatar_url":"https://github.com/copyleftdev.png","language":"Go","readme":"# randexc: Random Execution Library for Go\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/copyleftdev/randexc)](https://goreportcard.com/report/github.com/copyleftdev/randexc)\n[![GoDoc](https://godoc.org/github.com/copyleftdev/randexc?status.svg)](https://godoc.org/github.com/copyleftdev/randexc)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n`randexc` is a powerful and flexible Go library for executing actions at random times within a specified duration. It provides both synchronous and asynchronous execution options, making it suitable for a wide range of applications including load testing, simulating real-world events, and implementing sophisticated retry mechanisms.\n\n## Features\n\n- 🕒 Execute actions within a random time frame\n- 🔄 Support for both synchronous and asynchronous execution\n- 🛠 Configurable through functional options\n- 🧪 Easy to test with custom random sources\n- 📦 Lightweight with no external dependencies\n\n## Installation\n\n```bash\ngo get github.com/copyleftdev/randexc\n```\n\n## Quick Start\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"fmt\"\n    \"log\"\n\n    \"github.com/copyleftdev/randexc/pkg/randexc\"\n)\n\nfunc main() {\n    executor, err := randexc.New(\"1m\")\n    if err != nil {\n        log.Fatalf(\"Failed to create executor: %v\", err)\n    }\n\n    err = executor.Execute(context.Background(), func() error {\n        fmt.Println(\"Action executed at a random time within 1 minute!\")\n        return nil\n    })\n\n    if err != nil {\n        log.Printf(\"Execution failed: %v\", err)\n    }\n}\n```\n\n## Use Cases\n\n### Load Testing\n\nSimulate realistic user behavior in load tests by executing actions at random intervals:\n\n```go\nfunc performRequest() error {\n    // Simulate HTTP request\n    time.Sleep(100 * time.Millisecond)\n    return nil\n}\n\nexecutor, _ := randexc.New(\"5s\")\n\nfor i := 0; i \u003c 100; i++ {\n    go func() {\n        err := executor.Execute(context.Background(), performRequest)\n        if err != nil {\n            log.Printf(\"Request failed: %v\", err)\n        }\n    }()\n}\n```\n\n### Jittered Exponential Backoff\n\nImplement a jittered exponential backoff strategy for retrying operations:\n\n```go\nfunc retryWithBackoff(operation func() error) error {\n    baseDelay := 100 * time.Millisecond\n    maxDelay := 10 * time.Second\n    maxAttempts := 5\n\n    for attempt := 0; attempt \u003c maxAttempts; attempt++ {\n        jitteredDelay := time.Duration(float64(baseDelay) * (1 + rand.Float64()))\n        if jitteredDelay \u003e maxDelay {\n            jitteredDelay = maxDelay\n        }\n\n        executor, _ := randexc.New(jitteredDelay.String())\n        err := executor.Execute(context.Background(), operation)\n        if err == nil {\n            return nil\n        }\n\n        baseDelay *= 2\n    }\n\n    return fmt.Errorf(\"operation failed after %d attempts\", maxAttempts)\n}\n```\n\n### Simulating Real-world Events\n\nCreate more realistic simulations by introducing randomness in event timing:\n\n```go\nfunc simulateIoTDevice(deviceID string) {\n    executor, _ := randexc.New(\"1h\")\n\n    for {\n        executor.Execute(context.Background(), func() error {\n            temperature := 20 + rand.Float64()*10\n            humidity := 30 + rand.Float64()*20\n            fmt.Printf(\"Device %s: Temp: %.2f°C, Humidity: %.2f%%\\n\", deviceID, temperature, humidity)\n            return nil\n        })\n    }\n}\n\n// Simulate multiple IoT devices\nfor i := 0; i \u003c 5; i++ {\n    go simulateIoTDevice(fmt.Sprintf(\"device_%d\", i))\n}\n```\n\n## Documentation\n\nFor more detailed documentation and advanced usage examples, please see the [usage guide](docs/usage.md).\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcopyleftdev%2Frandexc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcopyleftdev%2Frandexc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcopyleftdev%2Frandexc/lists"}