summaryrefslogtreecommitdiffstats
path: root/common/resourcefacade.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-07 14:21:44 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-04-07 14:50:15 +0200
commit9fdcedf88e2fabedad73f0c74906318673f1ffa0 (patch)
treeeceba5dfb03e59c483ad83af8ae220894083473a /common/resourcefacade.cpp
parent8c7924171942f5f0d25c8a02f66d82f5be6edb5b (diff)
downloadsink-9fdcedf88e2fabedad73f0c74906318673f1ffa0.tar.gz
sink-9fdcedf88e2fabedad73f0c74906318673f1ffa0.zip
Better account status aggregation.
Only ever enter error state on non-recoverable errors. Otherwise: * Busy state while busy, then go back to online/offline/error. * If we failed connect during replay/sync we assume we're offline. * If we failed to login but could connect we have a known error condition. * If we succeeded to replay/sync something we are apprently online. At the core we have the problem that we have no way of telling wether we can connect to the server until we actually try (network is not enough: vpns, firewalls, ....). Further the status always reflects the latest status, so even if we were in an error state, once we retry we go out of the error state and either end up back in the error state or not. When aggregating states we have to similarly adjust the state to the most relevant among the resources. The states are ordered like this: * Error * Busy * Connected * Offline
Diffstat (limited to 'common/resourcefacade.cpp')
-rw-r--r--common/resourcefacade.cpp35
1 files changed, 14 insertions, 21 deletions
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp
index c702777..dee0711 100644
--- a/common/resourcefacade.cpp
+++ b/common/resourcefacade.cpp
@@ -351,7 +351,7 @@ QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain
351 const auto resources = Store::read<ApplicationDomain::SinkResource>(query); 351 const auto resources = Store::read<ApplicationDomain::SinkResource>(query);
352 SinkTraceCtx(ctx) << "Found resource belonging to the account " << account.identifier() << " : " << resources; 352 SinkTraceCtx(ctx) << "Found resource belonging to the account " << account.identifier() << " : " << resources;
353 auto accountIdentifier = account.identifier(); 353 auto accountIdentifier = account.identifier();
354 ApplicationDomain::Status status = ApplicationDomain::ConnectedStatus; 354 QList<int> states;
355 for (const auto &resource : resources) { 355 for (const auto &resource : resources) {
356 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier())); 356 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier()));
357 if (!monitoredResources->contains(resource.identifier())) { 357 if (!monitoredResources->contains(resource.identifier())) {
@@ -364,27 +364,20 @@ QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain
364 Q_ASSERT(ret); 364 Q_ASSERT(ret);
365 monitoredResources->insert(resource.identifier()); 365 monitoredResources->insert(resource.identifier());
366 } 366 }
367 367 states << resourceAccess->getResourceStatus();
368 //Figure out overall status
369 auto s = resourceAccess->getResourceStatus();
370 switch (s) {
371 case ApplicationDomain::ErrorStatus:
372 status = ApplicationDomain::ErrorStatus;
373 break;
374 case ApplicationDomain::OfflineStatus:
375 if (status == ApplicationDomain::ConnectedStatus) {
376 status = ApplicationDomain::OfflineStatus;
377 }
378 break;
379 case ApplicationDomain::ConnectedStatus:
380 break;
381 case ApplicationDomain::BusyStatus:
382 if (status != ApplicationDomain::ErrorStatus) {
383 status = ApplicationDomain::BusyStatus;
384 }
385 break;
386 }
387 } 368 }
369 const auto status = [&] {
370 if (states.contains(ApplicationDomain::ErrorStatus)) {
371 return ApplicationDomain::ErrorStatus;
372 }
373 if (states.contains(ApplicationDomain::BusyStatus)) {
374 return ApplicationDomain::BusyStatus;
375 }
376 if (states.contains(ApplicationDomain::ConnectedStatus)) {
377 return ApplicationDomain::ConnectedStatus;
378 }
379 return ApplicationDomain::OfflineStatus;
380 }();
388 account.setStatusStatus(status); 381 account.setStatusStatus(status);
389 }); 382 });
390 return qMakePair(KAsync::null<void>(), runner->emitter()); 383 return qMakePair(KAsync::null<void>(), runner->emitter());