Skip to content

Commit

Permalink
Fix method for checking if query has reached max attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
heitortsergent committed Dec 28, 2015
1 parent 1c8ef4c commit 668bdf4
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions KeenClient/KeenClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ - (BOOL)handleError:(NSError **)error withErrorMessage:(NSString *)errorMessage

- (void)runAsyncQuery:(KIOQuery *)keenQuery block:(void (^)(NSData *, NSURLResponse *, NSError *))block {
dispatch_async(self.uploadQueue, ^{
BOOL hasQueryWithMaxAttempts = [dbStore hasQueryWithMaxAttempts:[keenQuery convertQueryToData] queryType:keenQuery.queryType collection:[keenQuery.propertiesDictionary objectForKey:@"event_collection"] projectID:self.projectID maxAttempts:self.maxQueryAttempts queryTTL:self.queryTTL];
BOOL hasQueryWithMaxAttempts = [self hasQueryReachedMaxAttempts:keenQuery];

if(hasQueryWithMaxAttempts) {
KCLog(@"Not running query because it failed over %d times", self.maxQueryAttempts);
Expand Down Expand Up @@ -1048,7 +1048,7 @@ - (void)runAsyncMultiAnalysisWithQueries:(NSArray *)keenQueries block:(void (^)(
- (NSData *)runQuery:(KIOQuery *)keenQuery returningResponse:(NSURLResponse **)response error:(NSError **)error {
@synchronized(self) {
NSData *responseData = nil;
BOOL hasQueryWithMaxAttempts = [dbStore hasQueryWithMaxAttempts:[keenQuery convertQueryToData] queryType:keenQuery.queryType collection:[keenQuery.propertiesDictionary objectForKey:@"event_collection"] projectID:self.projectID maxAttempts:self.maxQueryAttempts queryTTL:self.queryTTL];
BOOL hasQueryWithMaxAttempts = [self hasQueryReachedMaxAttempts:keenQuery];

if(hasQueryWithMaxAttempts) {
KCLog(@"Not running query because it failed over %d times", self.maxQueryAttempts);
Expand Down Expand Up @@ -1147,7 +1147,7 @@ - (NSDictionary *)prepareQueriesDictionaryForMultiAnalysis:(NSArray *)keenQuerie
}

- (void)runQuery:(KIOQuery *)keenQuery finishedBlock:(void(^)(NSData *, NSURLResponse *, NSError *))block {
BOOL hasQueryWithMaxAttempts = [dbStore hasQueryWithMaxAttempts:[keenQuery convertQueryToData] queryType:keenQuery.queryType collection:[keenQuery.propertiesDictionary objectForKey:@"event_collection"] projectID:self.projectID maxAttempts:self.maxQueryAttempts queryTTL:self.queryTTL];
BOOL hasQueryWithMaxAttempts = [self hasQueryReachedMaxAttempts:keenQuery];

if(hasQueryWithMaxAttempts) {
KCLog(@"Not running query because it failed over %d times", self.maxQueryAttempts);
Expand All @@ -1170,12 +1170,7 @@ - (void)runQuery:(KIOQuery *)keenQuery finishedBlock:(void(^)(NSData *, NSURLRes
}

- (BOOL)hasQueryReachedMaxAttempts:(KIOQuery *)keenQuery {
BOOL queryReachedMaxAttempts = NO;

// call dbstore method to find query and check the attempts column
queryReachedMaxAttempts = [dbStore getQuery:[keenQuery convertQueryToData] queryType:keenQuery.queryType collection:[keenQuery.propertiesDictionary objectForKey:@"event_collection"] projectID:self.projectID];

return queryReachedMaxAttempts;
return [dbStore hasQueryWithMaxAttempts:[keenQuery convertQueryToData] queryType:keenQuery.queryType collection:[keenQuery.propertiesDictionary objectForKey:@"event_collection"] projectID:self.projectID maxAttempts:self.maxQueryAttempts queryTTL:self.queryTTL];
}

- (void)handleQueryAPIResponse:(NSURLResponse *)response
Expand Down

0 comments on commit 668bdf4

Please sign in to comment.