]> Some of my projects - localmylist.git/commitdiff
Add failed column to pending_request marking that a request failed with a data error.
authorAPTX <marek321@gmail.com>
Sat, 25 May 2013 20:51:46 +0000 (22:51 +0200)
committerAPTX <marek321@gmail.com>
Sat, 25 May 2013 20:51:46 +0000 (22:51 +0200)
A connection error is no reply in x time, while data errors have to be retried after x time.

anioni/anioni.cpp
localmylist-management/mainwindow.cpp
localmylist/database.cpp
localmylist/database.h
localmylist/share/schema/schema.sql

index a5eecfd42383959328af8fe32a7c20953ad7d707..f2de4fd93a58044923734b324f2e6a1bfd7bfd82 100644 (file)
@@ -69,7 +69,7 @@ void AniOni::handleUdpClientError()
 void AniOni::failRequests()
 {
        log("Clearing failed Requests", QtServiceBase::Information);
-       LocalMyList::instance()->database()->clearFailedPendingRequests();
+       LocalMyList::instance()->database()->clearPendingRequestConnectionErrors();
        LocalMyList::instance()->database()->clearFailedPendingMyListUpdateRequests();
 }
 
index 4c6990168f0d2480fe334833c60a13c8bae3cf8d..4aaaaed337c350e51f34a9af7c3fa7e03f165986 100644 (file)
@@ -268,7 +268,7 @@ void MainWindow::on_actionClearAnimeTitleData_triggered()
 
 void MainWindow::on_actionClearFailedRequests_triggered()
 {
-       LocalMyList::instance()->database()->clearFailedPendingRequests();
+       LocalMyList::instance()->database()->clearPendingRequestConnectionErrors();
        LocalMyList::instance()->database()->clearFailedPendingMyListUpdateRequests();
 }
 
index 43463fa9caa74137ca26dfc70f0660c2e16e3233..6e9f4340aee6db8a8b7de2a2a0fc283869f3cc10 100644 (file)
@@ -1022,7 +1022,7 @@ bool Database::addRequest(const PendingRequest &request)
 {
        QSqlQuery &q = prepare(
        "INSERT INTO pending_request VALUES(:aid, :eid, :fid, "
-       "               :ed2k, :size, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT) ");
+       "               :ed2k, :size, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT) ");
 
        q.bindValue(":aid", request.aid);
        q.bindValue(":eid", request.eid);
@@ -1041,6 +1041,7 @@ QList<PendingRequest> Database::getRequestBatch(int limit)
        "               (SELECT aid, eid, fid, ed2k, size FROM pending_request "
        "                       WHERE start IS NULL "
        "                               AND data_error_count <= 10 "
+       "                               AND failed IS NULL "
        "                       ORDER BY priority DESC, added ASC "
        "                       LIMIT :limit) "
        "       RETURNING aid, eid, fid, ed2k, size ");
@@ -1055,6 +1056,7 @@ QList<PendingRequest> Database::getRequestBatch(int limit)
 
        while (q.next())
        {
+               // TODO add readPendingRequest method
                PendingRequest request;
                request.aid = q.value(0).toInt();
                request.eid = q.value(1).toInt();
@@ -1329,7 +1331,7 @@ bool Database::pendingRequestDataError(const PendingRequest &request)
 {
        QSqlQuery &q = prepare(
        "UPDATE pending_request "
-       "       SET connection_error_count = 0, data_error_count = data_error_count + 1 "
+       "       SET connection_error_count = 0, data_error_count = data_error_count + 1, failed = now() "
        "       WHERE aid = :aid "
        "               AND eid = :eid "
        "               AND fid = :fid "
@@ -1375,13 +1377,14 @@ bool Database::clearFailedFileRenames()
                                "WHERE failed_rename = true");
 }
 
-bool Database::clearFailedPendingRequests(int minutes)
+bool Database::clearPendingRequestConnectionErrors(int minutes)
 {
        QSqlQuery &q = prepare(
        "UPDATE pending_request "
        "       SET start = NULL, connection_error_count = connection_error_count + 1 "
        "       WHERE start IS NOT NULL "
-       "               AND age(current_timestamp, start) > :interval ");
+       "               AND age(current_timestamp, start) > :interval "
+       "               AND failed IS NULL ");
        q.bindValue(":interval", QString::number(minutes) + " minutes");
 
        return exec(q);
index 5c71cc009a5fd1195921a51718af01d995a8b525..4d3585f44d1f032dd78f64b221deae4272d5a827 100644 (file)
@@ -117,7 +117,7 @@ public slots:
        bool clearFileRenames();
        bool clearFailedFileRenames();
 
-       bool clearFailedPendingRequests(int minutes = 10);
+       bool clearPendingRequestConnectionErrors(int minutes = 10);
        bool clearFailedPendingMyListUpdateRequests(int minutes = 10);
 
        bool truncateTitleData();
index 4a517e41f5fbf70e3e7bffe839d01a55a56ec5ff..649338f537010a0deb3b9946d638ffab274988f4 100644 (file)
@@ -201,6 +201,7 @@ CREATE TABLE pending_request (
        client_id integer NOT NULL DEFAULT 0,
        added timestamp without time zone DEFAULT now(),
        start timestamp without time zone,
+       failed timestamp without time zone DEFAULT NULL,
        connection_error_count integer NOT NULL DEFAULT 0,
        data_error_count integer NOT NULL DEFAULT 0,
        CONSTRAINT pending_request_pk PRIMARY KEY (aid, eid, fid, ed2k, size)