{"id":17233678,"url":"https://github.com/j7mbo/methodcallretrier","last_synced_at":"2025-04-14T01:54:06.914Z","repository":{"id":68009383,"uuid":"167836002","full_name":"J7mbo/MethodCallRetrier","owner":"J7mbo","description":"Go utility for handling the retrying of a function call on error up to X times","archived":false,"fork":false,"pushed_at":"2019-04-20T14:08:40.000Z","size":24,"stargazers_count":13,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-14T01:54:01.818Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/J7mbo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-01-27T17:19:05.000Z","updated_at":"2020-04-23T22:30:01.000Z","dependencies_parsed_at":"2023-04-16T09:17:05.540Z","dependency_job_id":null,"html_url":"https://github.com/J7mbo/MethodCallRetrier","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J7mbo%2FMethodCallRetrier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J7mbo%2FMethodCallRetrier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J7mbo%2FMethodCallRetrier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/J7mbo%2FMethodCallRetrier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/J7mbo","download_url":"https://codeload.github.com/J7mbo/MethodCallRetrier/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248809032,"owners_count":21164895,"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":[],"created_at":"2024-10-15T05:25:50.883Z","updated_at":"2025-04-14T01:54:06.891Z","avatar_url":"https://github.com/J7mbo.png","language":"Go","readme":"MethodCallRetrier\n-\n\n[![Build Status](https://travis-ci.org/J7mbo/MethodCallRetrier.svg?branch=master)](https://travis-ci.org/J7mbo/MethodCallRetrier)\n[![GoDoc](https://godoc.org/github.com/J7mbo/MethodCallRetrier?status.svg)](https://godoc.org/github.com/J7mbo/MethodCallRetrier)\n[![codecov](https://img.shields.io/codecov/c/github/j7mbo/MethodCallRetrier.svg)](https://codecov.io/gh/J7mbo/MethodCallRetrier)\n\nFeatures\n-\n\nRetry your method calls automatically when an `error` is returned up to a specified number of times, with a given wait time.\n\nExtremely useful for retrying HTTP calls in distributed systems, or anything else over the network that can error sporadically.\n\nAn example of using this library for everything from retrying connections to redis, to logging with elasticsearch, can\nbe found [here](https://github.com/J7mbo/palmago-streetview).\n\nInstallation\n-\n```bash\ngo get github.com/j7mbo/MethodCallRetrier/v2\n```\n\nUsage\n-\n\nInitialise the object with some options:\n\n```go\nMethodCallRetrier.New(waitTime time.Duration, maxRetries int64, exponent int64) \n```\n\nCall `ExecuteWithRetry` with your object and method you want to retry:\n\n```go\nExecuteWithRetry(\n\tobject interface{}, methodName string, args ...interface{},\n) (results []interface{}, errs []error, wasSuccessful bool)\n```\n\nAlternatively, call `ExecuteFuncWithRetry` and pass in a function that returns `error` to retry.\n\n```go\nExecuteFuncWithRetry(func() error) (errs []error, wasSuccessful bool)\n```\n\nYou can use it as follows:\n\n```go\nresults, errs, wasSuccessful := retrier.ExecuteWithRetry(yourObject, \"MethodToCall\", \"Arg1\", \"Arg2\", \"etc\")\n```\n\nThe results are an array of `interface{}` objects, (used for the dynamic method call), and an array of all errors.\nTo use the results, you must typecast the result to the expected type. In the case of an `int64`, for example:\n\n```go\nmyInt := results[0].(int64)\n```\n\nOr, to maintain type safety in userland, you can pass a function in instead and do all your retriable work in there:\n\n```go\nvar json string\n\nfunctionToRetry := func() error {\n    json, err = DoSomeFlakeyHttpCall()\n    \n    if err != nil {\n        return err\n    }\n    \n    return nil\n}\n\nif wasSuccessful, errs := retrier.ExecuteFuncWithRetry(funcToRetry); !wasSuccesful {\n    /* Do something with errs because we failed 3 times */\n    return\n}\n\nfmt.Println(json)\n```\n\nBe aware that this choice now requires you to work within the function scope, and that if you want to use the results of\nthe call outside of the scope of the function then you must declare it using `var result type` as shown above; but this\ndoes remove the requirement of a type assertion that you have to do with `ExecuteWithRetry`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj7mbo%2Fmethodcallretrier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fj7mbo%2Fmethodcallretrier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fj7mbo%2Fmethodcallretrier/lists"}