Add the same to PackageConf syncs, and make logic more robust
This commit is contained in:
parent
d3d19f4f2a
commit
10d43282b6
@ -823,9 +823,9 @@ bool PackageConf::set_package_confs(QSqlDatabase& p_db) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PackageConf::sync(QSqlDatabase& p_db) {
|
void PackageConf::sync(QSqlDatabase& p_db) {
|
||||||
bool oneshot = true;
|
bool task_succeeded = true;
|
||||||
while (oneshot) {
|
int attempt = 0;
|
||||||
oneshot = false;
|
while (!task_succeeded) {
|
||||||
try {
|
try {
|
||||||
QSqlQuery query(p_db);
|
QSqlQuery query(p_db);
|
||||||
|
|
||||||
@ -850,8 +850,13 @@ void PackageConf::sync(QSqlDatabase& p_db) {
|
|||||||
query.addBindValue(branch->id);
|
query.addBindValue(branch->id);
|
||||||
query.addBindValue(release->id);
|
query.addBindValue(release->id);
|
||||||
|
|
||||||
if (!query.exec()) {
|
attempt++;
|
||||||
qDebug() << "Failed to sync PackageConf:" << query.lastError().text();
|
task_succeeded = query.exec();
|
||||||
|
if (!task_succeeded) {
|
||||||
|
if (query.lastError().text().contains("database is locked")) {
|
||||||
|
int delay = 1000 * static_cast<int>(std::pow(2, attempt - 1));
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(delay));
|
||||||
|
} else task_succeeded = true;
|
||||||
}
|
}
|
||||||
} catch (...) {}
|
} catch (...) {}
|
||||||
}
|
}
|
||||||
@ -1240,10 +1245,12 @@ void Task::save(QSqlDatabase& p_db, int _packageconf_id) {
|
|||||||
query.addBindValue(QString::fromStdString(std::regex_replace(log->get(), std::regex(R"(^\s+)"), "")));
|
query.addBindValue(QString::fromStdString(std::regex_replace(log->get(), std::regex(R"(^\s+)"), "")));
|
||||||
query.addBindValue(id);
|
query.addBindValue(id);
|
||||||
task_succeeded = query.exec();
|
task_succeeded = query.exec();
|
||||||
|
attempt++;
|
||||||
if (!task_succeeded) {
|
if (!task_succeeded) {
|
||||||
qDebug() << "Failed to save task to database, retrying:" << query.lastError().text();
|
if (query.lastError().text().contains("database is locked")) {
|
||||||
int delay = 1000 * static_cast<int>(std::pow(2, attempt - 1));
|
int delay = 1000 * static_cast<int>(std::pow(2, attempt - 1));
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(delay));
|
std::this_thread::sleep_for(std::chrono::milliseconds(delay));
|
||||||
|
} else task_succeeded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user