create-circuit-breaker
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "create-circuit-breaker" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-274cf9b99be6f93f754ec8619e4afe64c5829d09a9a0ffeccb287bcf6a0b9e56. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Generate a circuit-breaker pattern implementation for PHP 8.4. Creates a resilient component with state management, fallback support, and metrics functionality to prevent cascading failures. Includes unit tests.
Introduction source: third_party · dykyi-roman · 0.0.1 Reference
SkillPi interpretation
- Tasks
- Generates Circuit Breaker pattern for PHP 8.4. Creates resilience component protecting against cascading failures with state management, fallback support, and metrics. Includes unit tests.
- Audience
- | Scenario | Example | |----------|---------| | External service calls | API integrations, payment gateways | | Database connections | Prevent connection exhaustion | | Cascading failures | Stop failure propagation | | Service degradation | Graceful fallback when service unavailable |
- Testing
- Not tested
Browse files
Frontmatter
name: create-circuit-breaker
description: Generates Circuit Breaker pattern for PHP 8.4. Creates resilience component protecting against cascading failures with state management, fallback support, and metrics. Includes unit tests.Circuit Breaker Generator
Creates Circuit Breaker pattern infrastructure for resilience and fault tolerance.
When to Use
| Scenario | Example |
|---|---|
| External service calls | API integrations, payment gateways |
| Database connections | Prevent connection exhaustion |
| Cascading failures | Stop failure propagation |
| Service degradation | Graceful fallback when service unavailable |
Component Characteristics
CircuitState Enum
- Closed: Normal operation, requests pass through
- Open: Failing, requests rejected immediately
- HalfOpen: Testing recovery, limited requests allowed
CircuitBreaker
- Wraps external service calls
- Tracks failures and successes
- Automatic state transitions
- Configurable thresholds and timeouts
CircuitBreakerConfig
- Failure threshold count
- Success threshold for recovery
- Open state timeout duration
Generation Process
Step 1: Generate Core Components
Path: src/Infrastructure/Resilience/CircuitBreaker/
CircuitState.php— Enum with state transitionsCircuitBreakerConfig.php— Configuration value objectCircuitBreakerException.php— Exception for open circuit
Step 2: Generate Circuit Breaker
Path: src/Infrastructure/Resilience/CircuitBreaker/
CircuitBreaker.php— Main implementation with state management
Step 3: Generate Factory and Registry
Path: src/Infrastructure/Resilience/CircuitBreaker/
CircuitBreakerFactory.php— Creates configured breakersCircuitBreakerRegistry.php— Per-service breaker management
Step 4: Generate Tests
CircuitStateTest.php— State transition testsCircuitBreakerTest.php— Breaker behavior tests
File Placement
| Component | Path |
|---|---|
| All Classes | src/Infrastructure/Resilience/CircuitBreaker/ |
| Unit Tests | tests/Unit/Infrastructure/Resilience/CircuitBreaker/ |
Naming Conventions
| Component | Pattern | Example |
|---|---|---|
| State Enum | CircuitState |
CircuitState |
| Config | CircuitBreakerConfig |
CircuitBreakerConfig |
| Main Class | CircuitBreaker |
CircuitBreaker |
| Factory | CircuitBreakerFactory |
CircuitBreakerFactory |
| Registry | CircuitBreakerRegistry |
CircuitBreakerRegistry |
| Exception | CircuitBreakerException |
CircuitBreakerException |
| Test | {ClassName}Test |
CircuitBreakerTest |
Quick Template Reference
CircuitState
enum CircuitState: string
{
case Closed = 'closed';
case Open = 'open';
case HalfOpen = 'half_open';
public function allowsRequest(): bool;
public function canTransitionTo(self $next): bool;
}
CircuitBreakerConfig
final readonly class CircuitBreakerConfig
{
public function __construct(
public int $failureThreshold = 5,
public int $successThreshold = 3,
public int $openTimeoutSeconds = 30,
public int $halfOpenMaxAttempts = 3
) {}
public static function default(): self;
public static function aggressive(): self;
public static function lenient(): self;
}
CircuitBreaker
final class CircuitBreaker
{
public function execute(callable $operation, ?callable $fallback = null): mixed;
public function canExecute(): bool;
public function getState(): CircuitState;
public function forceOpen(): void;
public function forceClose(): void;
}
Usage Example
$breaker = $circuitBreakers->get('payment-gateway');
try {
$result = $breaker->execute(
operation: fn() => $paymentClient->charge($request),
fallback: fn() => PaymentResult::deferred($request->id)
);
} catch (CircuitBreakerException $e) {
// Circuit is open
return PaymentResult::serviceUnavailable($request->id);
}
State Transitions
CLOSED ─────failure threshold reached────→ OPEN
↑ │
│ │ timeout elapsed
│ ↓
success threshold reached HALF-OPEN
└────────────────────────────────────────┘
│
failure in half-open
│
↓
OPEN
Anti-patterns to Avoid
| Anti-pattern | Problem | Solution |
|---|---|---|
| Global Circuit Breaker | One breaker for all services | Per-service breakers |
| No Fallback | Hard failure on open | Provide fallback strategy |
| Immediate Retry | Hammering failed service | Use timeout before HalfOpen |
| No Metrics | Can't monitor health | Log state transitions |
| Static Thresholds | Can't tune per service | Configurable per service |
| No Manual Override | Can't force open/close | Add force methods |
References
For complete PHP templates and examples, see:
references/templates.md— CircuitState, CircuitBreakerConfig, CircuitBreaker, Factory, Registry templatesreferences/examples.md— HTTP client, payment gateway examples and tests
Current listing version
0.0.1
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- Circuit Breaker 模式是微服务架构中的核心弹性模式,能有效防止级联故障
- 支持状态管理、回退机制和指标功能,提供完整的容错解决方案
- 适用于外部服务调用、数据库连接等多种高价值场景
Highlights
- description 精准描述了生成断路器模式的核心功能
- 触发词覆盖状态管理、回退支持、指标功能等关键特性
- 边界清晰,不易与其他 Skill 重叠
Highlights
- 文档结构完整,包含使用场景、组件特性、生成流程、文件路径等关键信息
- 提供了详细的命名规范和模板参考,便于开发者理解和使用
- 包含状态转换图和反模式说明,提升文档的实用性和完整性
Highlights
- 生成步骤清晰,从核心组件到工厂注册表的流程完整
- 提供了具体的文件路径和命名规范,确保生成的代码结构一致
- 包含使用示例和异常处理说明,提升代码的可靠性
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.