定制 zarganwar/failure-retry-executor 二次开发

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

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

zarganwar/failure-retry-executor

最新稳定版本:0.1.4

Composer 安装命令:

composer require zarganwar/failure-retry-executor

包简介

Retry failed operations

README 文档

README

Usage

Simply run function Zarganwar\FailureRetryExecutor\FailureRetryExecutor::execute() with your command as first argument

Zarganwar\FailureRetryExecutor\FailureRetryExecutor::execute(fn() => someFunction());

Your function will be executed and if it fails (throws an Exception or returns false), it will be executed again. Max. default retries is 3. Of course, you can change it by passing maxAttempts: int argument.

Zarganwar\FailureRetryExecutor\FailureRetryExecutor::execute(
    command: fn() => someFunction(),
    maxAttempts: 99,
);

You can also respond to the command result or failure by passing onSuccess: callable or/and onFailure: callable arguments.

Zarganwar\FailureRetryExecutor\FailureRetryExecutor::execute(
    command: fn() => someFunction(),
    onSuccess: fn($result /* Your callable command result */) => doSomething($result),
    onFailure: fn(Throwable $throwable) => log($throwable),
);

Example of usage:

// Some HTTP client
$client = new Client();
$logger = new Logger();

Zarganwar\FailureRetryExecutor\FailureRetryExecutor::execute(
    command: fn() => $client->get('https://example.com'),
    onSuccess: function(ResponseInterface $response): void 
    {       
        if ($response->getStatusCode() !== 200) {
            throw new Exception("Server responded with status code {$response->getStatusCode()} instead of 200");
        }
    },
    onFailure: fn(Throwable $throwable) => $logger->log($throwable),
    maxAttempts: 5,
);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-10-16