7Q_DECLARE_LOGGING_CATEGORY(ParameterManagerLog)
10 bool notifyFailure, std::function<
void(const QString &)> requestFn,
14 , _componentId(componentId)
15 , _notifyFailure(notifyFailure)
16 , _requestFn(std::move(requestFn))
17 , _pending(QSet<QString>(resolvedNames.cbegin(), resolvedNames.cend()))
18 , _retryBaseDelayMs(
QGC::runningUnitTests() ? 50 : kRetryBaseDelayMs)
20 _retryTimer.setSingleShot(
true);
21 connect(&_retryTimer, &QTimer::timeout,
this, &BulkRefreshJob::_sendPendingRequests);
24 _sendPendingRequests();
27void BulkRefreshJob::_sendPendingRequests()
29 qCDebug(ParameterManagerLog) <<
"BulkRefreshJob: round" << _round
30 <<
"\u2014 firing" << _pending.count() <<
"requests";
31 for (
const QString &name : std::as_const(_pending)) {
36void BulkRefreshJob::_onParamSuccess(
int componentId,
const QString ¶mName,
int )
38 if (componentId != _componentId) {
41 const bool wasPending = _pending.remove(paramName);
42 const bool wasFailed = _failed.remove(paramName);
43 if (!wasPending && !wasFailed) {
46 _checkRoundComplete();
49void BulkRefreshJob::_onParamFailure(
int componentId,
const QString ¶mName,
int )
51 if (componentId != _componentId || !_pending.remove(paramName)) {
54 _failed.insert(paramName);
55 _checkRoundComplete();
58void BulkRefreshJob::_checkRoundComplete()
60 if (!_pending.isEmpty()) {
66 if (_failed.isEmpty()) {
67 qCDebug(ParameterManagerLog) <<
"BulkRefreshJob: complete after round" << _round
68 <<
"\u2014 all params refreshed successfully";
74 const int delayMs = _retryBaseDelayMs << _round;
75 qCDebug(ParameterManagerLog) <<
"BulkRefreshJob: round" << _round
76 <<
"finished with" << _failed.count()
77 <<
"failures \u2014 retrying in" << delayMs <<
"ms";
78 _pending = std::move(_failed);
81 _retryTimer.start(delayMs);
83 qCDebug(ParameterManagerLog) <<
"BulkRefreshJob: complete after round" << _round
84 <<
"\u2014" << _failed.count() <<
"params still failed";
86 const QStringList failedList(_failed.cbegin(), _failed.cend());
87 QGC::showAppMessage(_mgr->tr(
"Parameter refresh failed for: %1").arg(failedList.join(QStringLiteral(
", "))),
88 _mgr->tr(
"Parameter Bulk Refresh"));
static constexpr int kMaxRetryRounds
Number of batch-level retry rounds before giving up.
void _paramRequestReadFailure(int componentId, const QString ¶mName, int paramIndex)
void _paramRequestReadSuccess(int componentId, const QString ¶mName, int paramIndex)
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.