I have already implemented NSOperationQueue successfully in application.
I have one operation queue which might have 1000 of NSOperations like below.
@interface Operations : NSOperation
@end
@implementation Operations
- (void)main
{
NSURL *url = [NSURL URLWithString:@"Your URL Here"];
NSString *contentType = @"application/json";
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSError *err = nil;
NSData *body = [NSJSONSerialization dataWithJSONObject:postVars options:NSJSONWritingPrettyPrinted error:&err];
[request setHTTPBody:body];
[request addValue:[NSString stringWithFormat:@"%lu", (unsigned long)body.length] forHTTPHeaderField: @"Content-Length"];
[request setTimeoutInterval:60];
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *resData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
}
@end
Now for that queue I am adding all 1000 operations at a time. I add operation like below.
Operations *operation = [[Operations alloc]init];
[downloadQueue addOperation:operation];
Now what happens time interval is 60 as [request setTimeoutInterval:60]
So think like after 60 seconds if 300 operations out of 1000 operations is finished then other 700 operations are throwing request time out error.
So what should I do in this case.
Can I resume failed operations? Or I should again make operation and add it in queue.
Is there any better mechanism than this one?