@bernierllc/nevar-loop-controller
v0.1.0
Published
Supervised loop management with heartbeat monitoring for the Nevar rules engine
Downloads
205
Readme
@bernierllc/nevar-loop-controller
Runtime loop lifecycle management for the Nevar rules engine. Controls opt-in infinite loop execution with heartbeat monitoring and concurrency limits.
Installation
npm install @bernierllc/nevar-loop-controllerUsage
import { LoopController } from '@bernierllc/nevar-loop-controller';
const controller = new LoopController({
allowInfiniteLoops: true,
maxConcurrentLoops: 5,
heartbeatIntervalMs: 5000,
maxMissedHeartbeats: 3,
});
// Check if loops are allowed
if (controller.isAllowed()) {
const handle = controller.startLoop('order.monitor');
if (handle) {
// Send heartbeats during execution
controller.heartbeat(handle.id);
// Inspect loop state
const state = controller.inspect(handle.id);
// Pause/resume
controller.pause(handle.id);
controller.resume(handle.id);
// Complete when done
controller.complete(handle.id);
}
}
// Kill stale loops that missed heartbeats
const killedIds = controller.checkHeartbeats();
// List all active loops
const active = controller.list();API
LoopController
Manages the lifecycle of opt-in infinite loops with heartbeat-based health monitoring.
Constructor: new LoopController(config?: Partial<LoopConfig>)
Default config: allowInfiniteLoops: false, maxConcurrentLoops: 0, heartbeatIntervalMs: 5000, maxMissedHeartbeats: 3
isAllowed()- Returnstrueif loops are enabled and concurrency limit is greater than zerostartLoop(triggerKey)- Creates a new loop handle. Returnsnullif loops are not allowed or at concurrency limitheartbeat(loopId)- Records a heartbeat and increments iteration count. Returnsfalseif loop not found or not runningkill(loopId)- Forcefully terminates a looppause(loopId)- Pauses a running loopresume(loopId)- Resumes a paused loopcomplete(loopId)- Marks a loop as completedlist()- Returns all active (running or paused) loop handlesinspect(loopId)- Returns the fullLoopHandlefor a given loop, ornullcheckHeartbeats()- Kills loops that have missed too many heartbeats. Returns array of killed loop IDsgetConfig()- Returns a copy of the current configuration
LoopControllerError
Error class for loop controller failures. Extends Error with code and context properties.
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.
License
Copyright (c) 2025 Bernier LLC. All rights reserved.
