Update the database on each server info poll

This commit is contained in:
Cameron Gutman 2016-01-21 12:09:49 -05:00
parent 9aa9b0fc5a
commit 1c1f22e047

View File

@ -11,6 +11,7 @@
#import "HttpManager.h" #import "HttpManager.h"
#import "ServerInfoResponse.h" #import "ServerInfoResponse.h"
#import "HttpRequest.h" #import "HttpRequest.h"
#import "DataManager.h"
@implementation DiscoveryWorker { @implementation DiscoveryWorker {
TemporaryHost* _host; TemporaryHost* _host;
@ -100,7 +101,12 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds
ServerInfoResponse* serverInfoResp = [self requestInfoAtAddress:address]; ServerInfoResponse* serverInfoResp = [self requestInfoAtAddress:address];
receivedResponse = [self checkResponse:serverInfoResp]; receivedResponse = [self checkResponse:serverInfoResp];
if (receivedResponse) { if (receivedResponse) {
[serverInfoResp populateHost:_host];
_host.activeAddress = address; _host.activeAddress = address;
// Update the database using the response
DataManager *dataManager = [[DataManager alloc] init];
[dataManager updateHost:_host];
break; break;
} }
} }
@ -137,7 +143,6 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds
if ([response isStatusOk]) { if ([response isStatusOk]) {
// If the response is from a different host then do not update this host // If the response is from a different host then do not update this host
if ((_host.uuid == nil || [[response getStringTag:TAG_UNIQUE_ID] isEqualToString:_host.uuid])) { if ((_host.uuid == nil || [[response getStringTag:TAG_UNIQUE_ID] isEqualToString:_host.uuid])) {
[response populateHost:_host];
return YES; return YES;
} else { } else {
Log(LOG_I, @"Received response from incorrect host: %@ expected: %@", [response getStringTag:TAG_UNIQUE_ID], _host.uuid); Log(LOG_I, @"Received response from incorrect host: %@ expected: %@", [response getStringTag:TAG_UNIQUE_ID], _host.uuid);