定制 gohany/retry 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gohany/retry

最新稳定版本:v1.0.5

Composer 安装命令:

composer require gohany/retry

包简介

Common interface for retrying operations

关键字:

README 文档

README

A tiny set of PHP interfaces for standardized retry behavior, plus a compact rtry: string you can store in one column and compile at runtime.

Features

  • Portable API: RetryerInterface::try(callable $op, RetryPolicyInterface $policy, array $context = []).
  • Single‑column policy with rtry: strings (backoff, jitter, deadlines, hedging hints).
  • Testable: ClockInterface + SleeperInterface → no real sleeps in unit tests.
  • Deciders: pluggable logic to map outcomes to retry/stop decisions.

Quick start

use Psr\Retry\Impl\RtryPolicyFactory;
use Psr\Retry\Impl\RtryPolicy;
use foreup\rest\models\services\Retry;
use foreup\rest\models\services\NativeSleeper;
use Psr\Clock\ClockInterface;

// Construct runtime pieces (DI in real apps)
$factory = new RtryPolicyFactory();
$policy = $factory->fromSpec('rtry:a=5;d=250ms;mode=exp;b=2;cap=5s;jmode=full;on=5xx,ETIMEDOUT');

$retryer = new Retry($clock /* PSR-20 */, new NativeSleeper());

$response = $retryer->try(function ($ctx) use ($httpClient, $request) {
    $res = $httpClient->sendRequest($request);
    if ($res->getStatusCode() >= 500) {
        throw new RuntimeException('server_error');
    }
    return $res;
}, $policy, ['tenant_id' => 12345, 'correlation_id' => 'req-abc123']);

Interfaces (overview)

  • RetryerInterface — runs the callable under a policy.
  • RetryPolicyInterface — attempts, delays, jitter, deadlines, hedging hints, decider.
  • RetryPolicyFactoryInterface — parses rtry: into a policy.
  • AttemptContextInterface — attempt #, elapsed, remaining budget, context.
  • AttemptOutcomeInterface — result or error for deciders.
  • JitterSpecInterface — deterministic jitter application.
  • RetryDeciderInterface — retry/stop decision.

See SPEC.md for normative details and the full RTRY grammar.

Testing

Provide a test SleeperInterface that records sleep calls instead of actually sleeping, and a fixed ClockInterface (PSR‑20) for deterministic timing.

Contributing

  1. Open issues/PRs here to refine the draft.
  2. If there’s interest, we’ll form a Working Group and seek a Sponsor inside PHP‑FIG.

License

  • Code (interfaces, reference impl): MIT
  • Spec/docs (SPEC.md, this README): CC‑BY 4.0

Attribution/NOTICE

© 2025 Gregory Riley and contributors. Licensed under Creative Commons Attribution 4.0 (CC BY 4.0). Changes may have been made. License: https://creativecommons.org/licenses/by/4.0/

Reference implementation (non-normative)

A production-ready reference implementation lives here:

This implementation is provided to demonstrate how the interfaces and the rtry: policy can be used in practice. It is non-normative and does not change the meaning of this spec.

统计信息

  • 总下载量: 627
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固