~ci-train-bot/sync-monitor/sync-monitor-ubuntu-yakkety-landing-053

« back to all changes in this revision

Viewing changes to src/sync-account.cpp

  • Committer: CI Train Bot
  • Author(s): Renato Araujo Oliveira Filho
  • Date: 2016-04-19 19:32:27 UTC
  • mfrom: (58.1.8 last-sync-property)
  • Revision ID: ci-train-bot@canonical.com-20160419193227-7zthaqsx3bsyx0lf
Export the last successful sync data.
Approved by: Arthur Mello

Show diffs side-by-side

added added

removed removed

Lines of Context:
210
210
    return m_state;
211
211
}
212
212
 
213
 
QStringMap SyncAccount::lastReport(const QString &serviceName) const
 
213
QStringMap SyncAccount::lastReport(const QString &serviceName, bool onlySuccessful) const
214
214
{
 
215
    static QStringList okStatus;
 
216
 
 
217
    if (okStatus.isEmpty()) {
 
218
        okStatus << "0"
 
219
                 << "200"
 
220
                 << "204"
 
221
                 << "207";
 
222
    }
215
223
    const uint pageSize = 100;
216
224
    uint index = 0;
217
225
    if (!m_currentSession) {
228
236
 
229
237
    QString sessionName = this->sessionName(serviceName);
230
238
    index += pageSize;
231
 
    while (reports.size() != pageSize) {
 
239
    while (true) {
232
240
        Q_FOREACH(const QStringMap &report, reports) {
233
241
            if (report.value("peer") == sessionName) {
234
 
                return report;
 
242
                if (onlySuccessful) {
 
243
                    QString status = report.value("status", "");
 
244
                    if (okStatus.contains(status)) {
 
245
                        return report;
 
246
                    }
 
247
                } else {
 
248
                    return report;
 
249
                }
235
250
            }
236
251
        }
 
252
 
 
253
        if (reports.size() != pageSize)
 
254
            break;
 
255
 
237
256
        reports = m_currentSession->reports(index, pageSize);
238
257
        index += pageSize;
239
258
    }
240
259
 
241
 
    Q_FOREACH(const QStringMap &report, reports) {
242
 
        if (report.value("peer") == sessionName) {
243
 
            return report;
244
 
        }
245
 
    }
246
 
 
247
260
    return QStringMap();
248
261
}
249
262
 
402
415
    m_retrySync = retry;
403
416
}
404
417
 
 
418
QString SyncAccount::lastSuccessfulSyncDate(const QString &serviceName)
 
419
{
 
420
    if (m_currentSession) {
 
421
        qWarning() << "Sync in progress can not load log right now";
 
422
        return QDateTime::currentDateTime().toUTC().toString(Qt::ISODate);
 
423
    }
 
424
 
 
425
    prepareSession(serviceName);
 
426
 
 
427
    QString lastSyncDate;
 
428
    QStringMap report = lastReport(serviceName, true);
 
429
    if (report.contains("start")) {
 
430
        uint lastSync = report["start"].toUInt();
 
431
        lastSyncDate = QDateTime::fromTime_t(lastSync).toUTC().toString(Qt::ISODate);
 
432
    }
 
433
 
 
434
    releaseSession();
 
435
 
 
436
    return lastSyncDate;
 
437
}
 
438
 
405
439
void SyncAccount::onAccountEnabledChanged(const QString &serviceName, bool enabled)
406
440
{
407
441
    // empty service name means that the hole account has been enabled/disabled