1
0
forked from BRT/arc

Add timeout handling and process kill logic for ADB operations. Refine date and time validation in transaction fetching. Adjust EventHandler to handle "ozon" bank accounts separately. Use blocking queued connection for stopping EventHandler.

This commit is contained in:
slava 2026-04-10 15:44:55 +07:00
parent 0c1d2675b3
commit 14ca8348c3
4 changed files with 51 additions and 22 deletions

View File

@ -358,13 +358,26 @@ void GetLastTransactionsScript::searchTransaction(const DeviceInfo &device, int
if (!txTime.isValid()) txTime = QDateTime::fromString(dtStr, "dd.MM.yyyy,HH:mm");
if (txTime.isValid()) txTime.setTimeZone(msk);
// Проверяем что дата совпадает (тот же день)
if (txTime.isValid() && txTime.date() != searchDate) {
// Проверяем что дата и время совпадают (±1 час от m_searchTime)
if (txTime.isValid()) {
if (txTime.date() != searchDate) {
qDebug() << "[FetchTransactions] Wrong date:" << dtStr << "expected" << searchDate;
AdbUtils::goBack(m_deviceId);
QThread::msleep(1000);
continue;
}
if (m_searchTime.isValid()) {
const qint64 diffSecs = qAbs(txTime.toUTC().secsTo(m_searchTime.toUTC()));
if (diffSecs > 3600) {
qDebug() << "[FetchTransactions] Time mismatch:" << dtStr
<< "expected" << searchMsk.toString("dd.MM.yyyy, HH:mm")
<< "diff=" << diffSecs << "sec";
AdbUtils::goBack(m_deviceId);
QThread::msleep(1000);
continue;
}
}
}
// Нашли!
qDebug() << "[FetchTransactions] FOUND transaction:"

View File

@ -103,7 +103,7 @@ void startEventHandler(const QCoreApplication &app) {
QObject::connect(eventHandler, &EventHandler::finished, eventHandler, &QObject::deleteLater);
QObject::connect(thread, &QThread::finished, thread, &QThread::deleteLater);
QObject::connect(&app, &QCoreApplication::aboutToQuit, [=]() {
eventHandler->stop();
QMetaObject::invokeMethod(eventHandler, "stop", Qt::BlockingQueuedConnection);
});
thread->start();
}

View File

@ -455,6 +455,8 @@ QByteArray DeviceScreener::takeScreenshot(const QString &deviceId) {
if (!process.waitForFinished(5000)) {
qWarning() << "ADB скриншот не завершился для" << deviceId;
process.kill();
process.waitForFinished(1000);
return {};
}
@ -477,7 +479,12 @@ QList<QPair<QString, QString> > DeviceScreener::readAdbDevices() {
qWarning() << "[DeviceScreener] Failed to start adb devices:" << process.errorString();
return {};
}
process.waitForFinished(10000);
if (!process.waitForFinished(10000)) {
qWarning() << "[DeviceScreener] adb devices timeout";
process.kill();
process.waitForFinished(1000);
return {};
}
const QString output = process.readAllStandardOutput();
QList<QPair<QString, QString> > devices;

View File

@ -281,6 +281,14 @@ void EventHandler::updateEventThread(const QString &key, const EventInfo &event,
QJsonValue taskData;
if (event.type == EventType::FetchProfile) {
if (event.bankName == "ozon") {
EventDAO::updateEventAmount(event.id, account.amount);
QJsonObject obj;
obj["bank_account_id"] = account.materialId;
obj["amount"] = static_cast<int>(account.amount * 100);
obj["currency"] = currencyCode;
taskData = obj;
} else {
// Отправляем суммы всех материалов устройства для этого банка
const QList<MaterialInfo> allAccounts = MaterialDAO::getAccounts(event.deviceId, event.bankName);
if (!allAccounts.isEmpty()) {
@ -302,6 +310,7 @@ void EventHandler::updateEventThread(const QString &key, const EventInfo &event,
obj["currency"] = currencyCode;
taskData = obj;
}
}
} else if (event.type == EventType::FetchTransactions) {
QList<TransactionInfo> txList = TransactionDAO::getTransactionsWithinHours(event.accountId, 24);
// Фильтруем: отправляем только транзакции с bank_transaction_id