@bernierllc/nevar-circuit-breaker
v0.1.0
Published
Circuit breaker for the Nevar rules engine - configurable depth, action, time, and concurrency limits
Downloads
232
Readme
@bernierllc/nevar-circuit-breaker
Circuit breaker for the Nevar rules engine suite. Provides configurable hard limits for cascade depth, actions per chain, chain duration, and concurrent chain execution.
Installation
npm install @bernierllc/nevar-circuit-breakerUsage
import { CircuitBreaker } from '@bernierllc/nevar-circuit-breaker';
const breaker = new CircuitBreaker({
maxCascadeDepth: 5,
maxActionsPerChain: 25,
maxChainDurationMs: 10_000,
maxConcurrentChains: 50,
});
// Check limits before proceeding
breaker.checkDepth(currentDepth);
breaker.checkActions(actionCount);
breaker.checkDuration(startTime);
// Manage concurrency
if (breaker.acquireChain()) {
try {
// ... execute chain
} finally {
breaker.releaseChain();
}
}API
CircuitBreaker
Enforces hard limits on rule chain execution to prevent runaway cascades.
Constructor: new CircuitBreaker(config?: Partial<CircuitBreakerConfig>)
Default config: maxCascadeDepth: 10, maxActionsPerChain: 50, maxChainDurationMs: 30000, maxConcurrentChains: 100
checkDepth(currentDepth)- ThrowsNevarCircuitBreakerErrorif depth exceedsmaxCascadeDepthcheckActions(actionCount)- ThrowsNevarCircuitBreakerErrorif count exceedsmaxActionsPerChaincheckDuration(startTime)- ThrowsNevarCircuitBreakerErrorif elapsed time exceedsmaxChainDurationMsacquireChain()- Attempts to acquire a concurrency slot. Returnstrueif under limit,falseif at capacityreleaseChain()- Releases a concurrency slotgetConfig()- Returns a copy of the current configurationgetActiveChains()- Returns the number of currently active chains
Integration Documentation
Logger Integration
This package does not integrate with @bernierllc/logger. As a core package, logger integration is optional and not included by default. Consumers should handle logging at the service layer.
NeverHub Integration
This package does not integrate with @bernierllc/neverhub-adapter. As a core package, NeverHub integration is not applicable. NeverHub registration should be handled by service-layer packages that compose this package.
