zarganwar/failure-retry-executor 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱: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,
);

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固