承接 pransteter/etr-circuit-break-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

pransteter/etr-circuit-break-php

Composer 安装命令:

composer require pransteter/etr-circuit-break-php

包简介

A little library to offer a simple manager of circuit breaker pattern.

README 文档

README

Usage:

// Configure

// - 1: Create a repository to persist and get the state:
class MyAppCBStateRepository implements \Pransteter\MinimalCB\Contracts\StateRepository
{
    public function saveState(string $index, \stdClass $state): bool
    {
        // code to save a state.
    }
    public function getState(string $index): ?\stdClass
    {
        // code to find a state.
    }
}

$repository = new MyAppCBStateRepository();

// - 2: Create a object of Configuration to set CB settings:
$configuration = new \Pransteter\MinimalCB\DTOs\Configuration(
    processIdentifier: 'get-weather-data-from-api',
    failedTriesLimit: 5,
    secondsToStayOpened: 300,
);

// Initialize MinimalCB:
$cb = new MinimalCB(
    $configuration,
    $repository,
)->begin();

// Check if can be executed
if($cb->canExecute()) {
    // procede with execution and get the result.
    try {
        // - In case of success
        $cb->end(true);
    } catch (\Throwable $e) {
        // - executed with failure
        $cb->end(false);
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-11