Slight changes to error handling during RtcomEventLogger insertions to better handle...
authorJamie Thompson <jamie@.(none)>
Thu, 25 Aug 2011 01:48:58 +0000 (02:48 +0100)
committerJamie Thompson <jamie@.(none)>
Thu, 25 Aug 2011 01:48:58 +0000 (02:48 +0100)
DBBackends/RtcomEventLogger.cpp

index 264b65a..20daa23 100644 (file)
@@ -276,13 +276,13 @@ void RtcomEventLogger::Insert(EventTypes::iEvent &event, const NumberToNameLooku
                        // Add the event
                        QDateTime startTime(QDateTime::currentDateTimeUtc());
                        int newEventID(-1);
+                       int currentBackoffInMillisecs(5);
                        while(((newEventID = rtcom_el_add_event_full(el, revent, rheaders, rattachments, &error)) == -1)
-                                 && startTime.msecsTo(QDateTime::currentDateTimeUtc()) < 1000)
+                                 && startTime.msecsTo(QDateTime::currentDateTimeUtc()) < 10000)
                        {
                                if(error != NULL)
                                {
                                        qDebug() << "err: " << error->message;
-                                       qDebug() << *revent << "\n";
                                        g_error_free(error);
                                        error = NULL;
                                }
@@ -292,18 +292,24 @@ void RtcomEventLogger::Insert(EventTypes::iEvent &event, const NumberToNameLooku
                                mutex.lock();
 
                                QWaitCondition waitCondition;
-                               waitCondition.wait(&mutex, 5);
+                               waitCondition.wait(&mutex, currentBackoffInMillisecs);
 
                                mutex.unlock();
+
+                               // Exponential backoff...
+                               currentBackoffInMillisecs *= 2;
                        }
 
                        if(-1 == newEventID)
                        {
+                               qDebug() << "Unable to insert event due to error.";
+                               qDebug() << *revent << "\n";
+                       }
+                       else
+                       {
                                qDebug() << "new id: " << newEventID;
                                InsertedIDs().append(newEventID);
                        }
-                       else
-                               qDebug() << "Unable to insert event due to error.";
 
                        // Release the attachments
                        g_list_foreach (rattachments, (GFunc) rtcom_el_free_attachment, NULL);