5 Action action,
int failureThreshold,
8 , _action(std::move(action))
9 , _failureThreshold(failureThreshold)
10 , _resetTimeoutMsecs(resetTimeoutMsecs)
18 qCDebug(QGCStateMachineLog) <<
stateName() <<
"circuit breaker reset";
26 if (_tripTimer.elapsed() >= _resetTimeoutMsecs) {
29 qCDebug(QGCStateMachineLog) <<
stateName() <<
"circuit half-open, testing recovery";
32 qCDebug(QGCStateMachineLog) <<
stateName() <<
"circuit open, failing fast ("
33 << (_resetTimeoutMsecs - _tripTimer.elapsed()) <<
"ms until retry)";
41 qCDebug(QGCStateMachineLog) <<
stateName() <<
"executing action (state:"
52 qCDebug(QGCStateMachineLog) <<
stateName() <<
"recovery successful, resetting circuit";
62 qCDebug(QGCStateMachineLog) <<
stateName() <<
"action failed, count:"
63 << _failureCount <<
"/" << _failureThreshold;
69 qCDebug(QGCStateMachineLog) <<
stateName() <<
"half-open test failed, circuit re-opened";
70 }
else if (_failureCount >= _failureThreshold) {
74 qCDebug(QGCStateMachineLog) <<
stateName() <<
"failure threshold reached, circuit tripped";
std::function< bool()> Action
void tripped()
Emitted when the circuit trips (too many failures)
void succeeded()
Emitted when action succeeds.
void failed()
Emitted when action fails (or circuit is open)
void reset()
Manually reset the circuit breaker.
void onEnter() override
Override to perform actions on state entry.
void circuitReset()
Emitted when the circuit resets (after successful half-open test)
CircuitBreakerState(const QString &stateName, QState *parent, Action action, int failureThreshold=5, int resetTimeoutMsecs=30000)
@ Closed
Normal operation.
@ Open
Tripped, failing fast.
@ HalfOpen
Testing if service recovered.
QString stateName() const
Full-featured base class for QGroundControl state machine states.