{"id":20756496,"url":"https://github.com/basiliscos/perl-algorithm-backoff","last_synced_at":"2025-07-08T16:37:53.098Z","repository":{"id":153550155,"uuid":"80497083","full_name":"basiliscos/perl-Algorithm-Backoff","owner":"basiliscos","description":"perl-Algorithm-Backoff","archived":false,"fork":false,"pushed_at":"2017-03-15T07:57:26.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-18T04:31:42.015Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl","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/basiliscos.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","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":"2017-01-31T06:29:29.000Z","updated_at":"2017-01-31T06:29:47.000Z","dependencies_parsed_at":"2023-05-19T11:00:26.023Z","dependency_job_id":null,"html_url":"https://github.com/basiliscos/perl-Algorithm-Backoff","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/basiliscos%2Fperl-Algorithm-Backoff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basiliscos%2Fperl-Algorithm-Backoff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basiliscos%2Fperl-Algorithm-Backoff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basiliscos%2Fperl-Algorithm-Backoff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/basiliscos","download_url":"https://codeload.github.com/basiliscos/perl-Algorithm-Backoff/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243064358,"owners_count":20230550,"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-11-17T09:32:47.035Z","updated_at":"2025-03-11T15:49:19.681Z","avatar_url":"https://github.com/basiliscos.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# VERSION\n\nVersion 0.01\n\n# STATUS\n\n# SYNOPSIS\n\n    use Algorithm::Backoff;\n\n    my $backoff = Algorithm::Backoff-\u003enew(\n        min   =\u003e 0.1,\n        max   =\u003e 5,\n    );\n\n    my $some_service = Some::Service-\u003enew;\n\n    while (1) {\n        my $delay = $backoff-\u003enext_value;\n        sleep($delay);\n        my $result = eval { $some_service-\u003erun; 1 };\n        if ($result) {\n            # seems all fine with service\n            $backoff-\u003ereset_value;\n        } else {\n            # Ooops! We failed\n            warn \"Service failed: $@\" if @$;\n            warn \"Alarm! Too many service  failures!\"\n                if $backoff-\u003elimit_reached;\n\n        }\n    }\n\nIn case of `some_service` failures, this snipplet will sleep\n0, 0.1, 0.2, 0.4 ... 3.2, seconds before next attempt to launch\n`some_service` again. If it continue to fail it the sleep delay\nbefore next attempts will be `5`, and it will emit additional\nwarnings.\n\n# DESCRIPTION\n\nThe backoff algorihm generates sequence of numbers, each one\nis just doubled previous value until it hits maximum. The first\nvalue is by convension zero.\n\nThis numbers are useful, for example, when some service is\nchoking under load (or restarting), and instead of endlessly\npoll it like\n\n    while(1) {\n        try {\n            $service-\u003econnect;\n            $service-\u003eget_something;\n        };\n    }\n\nThe algorim allows to poll it in more polite manner, i.e.\nwith increasing delay with each next attempt.\n\n# STATIC METHODS\n\n## new($class, min =\u003e $min\\_value, max =\u003e $max\\_value)\n\nCreates new backoff instance which will operate in\nthe defined `$min_value` .. `$max_value` range.\n\nBackoff object remembers it's state between invocations.\n\n# METHODS\n\n## next\\_value\n\nReturns next backoff value. It can be used for `sleep`, if the value\ngiven range is in seconds.\n\n## limit\\_reached\n\nReturns `true` if limit has been reached with the last `next_value`\ninvocation. Intended to attract attention of the responsible personnel,\ni.e. emit warning, send SMS etc.\n\n## reset\\_value\n\nResets internal state. The following `next_value` invocation will\ngive 0.\n\n# AUTHOR\n\nBinary.com, `\u003csupport at binary.com\u003e`\n\n# BUGS\n\nPlease report any bugs or feature requests to https://github.com/binary-com/perl-Algorithm-Backoff/issues.\n\n# LICENSE AND COPYRIGHT\n\nCopyright 2017 Binary.com.\n\nThis program is free software; you can redistribute it and/or modify it\nunder the terms of the the Artistic License (2.0). You may obtain a\ncopy of the full license at:\n\n[http://www.perlfoundation.org/artistic\\_license\\_2\\_0](http://www.perlfoundation.org/artistic_license_2_0)\n\nAny use, modification, and distribution of the Standard or Modified\nVersions is governed by this Artistic License. By using, modifying or\ndistributing the Package, you accept this license. Do not use, modify,\nor distribute the Package, if you do not accept this license.\n\nIf your Modified Version has been derived from a Modified Version made\nby someone other than you, you are nevertheless required to ensure that\nyour Modified Version complies with the requirements of this license.\n\nThis license does not grant you the right to use any trademark, service\nmark, tradename, or logo of the Copyright Holder.\n\nThis license includes the non-exclusive, worldwide, free-of-charge\npatent license to make, have made, use, offer to sell, sell, import and\notherwise transfer the Package with respect to any patent claims\nlicensable by the Copyright Holder that are necessarily infringed by the\nPackage. If you institute patent litigation (including a cross-claim or\ncounterclaim) against any party alleging that the Package constitutes\ndirect or contributory patent infringement, then this Artistic License\nto you shall terminate on the date that such litigation is filed.\n\nDisclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER\nAND CONTRIBUTORS \"AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR\nPURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY\nYOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR\nCONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR\nCONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,\nEVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasiliscos%2Fperl-algorithm-backoff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasiliscos%2Fperl-algorithm-backoff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasiliscos%2Fperl-algorithm-backoff/lists"}