{"id":17026228,"url":"https://github.com/kevboh/ktbtaskqueue","last_synced_at":"2025-03-22T17:31:13.161Z","repository":{"id":13670510,"uuid":"16364182","full_name":"kevboh/KTBTaskQueue","owner":"kevboh","description":"A persistent (or not) queue to try and retry tasks until they succeed (or not).","archived":false,"fork":false,"pushed_at":"2016-06-16T13:58:50.000Z","size":40,"stargazers_count":31,"open_issues_count":1,"forks_count":16,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-01T17:47:38.212Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevboh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-30T00:29:11.000Z","updated_at":"2019-01-21T03:17:16.000Z","dependencies_parsed_at":"2022-09-23T14:00:20.375Z","dependency_job_id":null,"html_url":"https://github.com/kevboh/KTBTaskQueue","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevboh%2FKTBTaskQueue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevboh%2FKTBTaskQueue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevboh%2FKTBTaskQueue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevboh%2FKTBTaskQueue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevboh","download_url":"https://codeload.github.com/kevboh/KTBTaskQueue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244236094,"owners_count":20420752,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T07:31:11.320Z","updated_at":"2025-03-22T17:31:12.804Z","avatar_url":"https://github.com/kevboh.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KTBTaskQueue\n\n[![Build Status](https://travis-ci.org/kevboh/KTBTaskQueue.png?branch=master)](https://travis-ci.org/kevboh/KTBTaskQueue)\n[![Version](http://cocoapod-badges.herokuapp.com/v/KTBTaskQueue/badge.png)](http://cocoadocs.org/docsets/KTBTaskQueue)\n[![Platform](http://cocoapod-badges.herokuapp.com/p/KTBTaskQueue/badge.png)](http://cocoadocs.org/docsets/KTBTaskQueue)\n\n`KTBTaskQueue` is an optionally persistent queue that makes sure tasks get finished. It will prompt a delegate or block with a task until that task is declared successful or abandoned. Failed tasks can be retried immediately or at some point in the future, with the default following an exponential backoff pattern. The basic flow goes like this:\n\n1. Put a task in the queue.\n2. The queue hands the task to its delegate or an execution block. Whatever is executing the task... executes the task. You decide what executing a task looks like.\n3. If the task is successful it's removed from the queue. If not, it's kept around and retried until it succeeds or it reaches a `maxRetries` threshold, after which it is abandoned and removed from the queue.\n\n`KTBTaskQueue` can be used to track any task you wish. I find it useful to make sure network requests are successful when online and to keep them for later when offline.\n\n## Using It\n\nKTBTaskQueue is available through [CocoaPods](http://cocoapods.org), to install\nit simply add the following line to your Podfile:\n\n    pod \"KTBTaskQueue\"\n\nThen in code, let’s say you use [AFNetworking](https://github.com/AFNetworking/AFNetworking) and want to make sure a particularly important POST reaches your server. You could do something like:\n\n```\n// You created this queue in your app delegate or view controller or model.\n[self.queue enqueueTaskWithName:@\"PostThisVitalThing\" userInfo:@{\"wow\" : \"so important\"}];\n```\n\nOkay, now the queue will bug its delegate until the `PostThisVitalThing` task is complete. In the delegate:\n\n```\n- (void)taskQueue:(KTBTaskQueue *)queue executeTask:(KTBTask *)task completion:(KTBTaskCompletionBlock)completion {\n    // The task's userInfo is this request's parameters\n    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];\n    [manager POST:@\"http://example.com/resources.json\" parameters:task.userInfo success:^(AFHTTPRequestOperation *operation, id responseObject) {\n        NSLog(@\"JSON: %@\", responseObject);\n        completion(KTBTaskStatusSuccess);\n    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {\n        NSLog(@\"Error: %@\", error);\n        completion(KTBTaskStatusFailure);\n    }];\n}\n```\n\nBy default, `PostThisVitalThing` will be retried after failure up to 10 times. That number can be customized, along with tons of other aspects of a task, by using a longer constructor available through `KTBTask`:\n\n```\n[self.queue enqueueTask:[KTBTask taskWithName:@\"FutureTask\"\n                                     userInfo:nil\n                                availableDate:[NSDate dateWithTimeIntervalSinceNow:60]\n                                   maxRetries:3\n                                   useBackoff:NO]];\n```\n\n`FutureTask` won't be attempted until a minute from now, will only be retried 3 times (for a total of four attempts), and will be retried immediately upon failure—the queue won't delay retry using its backoff technique.\n\nThe `KTBTaskQueueDelegate` offers more flexibility. It includes optional methods to report when tasks are abandoned and allows a custom delay to be applied in place of the built-in backoff delay. Check out `KTBTaskQueue.h` and `KTBTaskQueueDelegate.h` for more details and things to play with.\n\nThere's also an `executionBlock` property on `KTBTaskQueue` if you hate the delegate pattern:\n\n```\n// Set the block that does the task\nqueue.executionBlock = ^(KTBTask *task, KTBTaskCompletionBlock completion) {\n    // The task's userInfo is this request's parameters\n    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];\n    [manager POST:@\"http://example.com/resources.json\" parameters:task.userInfo success:^(AFHTTPRequestOperation *operation, id responseObject) {\n        NSLog(@\"JSON: %@\", responseObject);\n        completion(KTBTaskStatusSuccess);\n    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {\n        NSLog(@\"Error: %@\", error);\n        completion(KTBTaskStatusFailure);\n    }];\n};\n// Enqueue the task\n[self.queue enqueueTaskWithName:@\"PostThisVitalThing\" userInfo:@{\"wow\" : \"so important\"}];\n```\n\nAlso worth mentioning is the `KTBTaskAlwaysRetry` value, which will prevent a queue from abandoning a task due to too many retries:\n\n```\n[self.queue enqueueTask:[KTBTask taskWithName:@\"IReallyWantThisDone\"\n                                     userInfo:nil\n                                availableDate:nil\n                                   maxRetries:KTBTaskAlwaysRetry\n                                   useBackoff:YES]];\n```\n\nThis task is available immediately (`availableDate` defaults to now) and will retry until it succeeds or the Earth is dust (or you drop your phone in the toilet). Whichever comes first.\n\n## Requirements\n\nARC, iOS 6+, and [FMDB](https://github.com/ccgus/fmdb) by Gus Mueller. FMDB will be imported automatically by CocoaPods. Don't worry; it's super-small.\n\n## Feedback\n\nPlease feel free to open issues and submit pull requests here. Thanks!\n\n## Author\n\nKevin Barrett, kevin@kevboh.com\n\nLike this sort of thing? Check out [Postlight](https://www.postlight.com), a digital agency that builds big, beautiful sites and apps.\n\n## License\n\nKTBTaskQueue is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevboh%2Fktbtaskqueue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevboh%2Fktbtaskqueue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevboh%2Fktbtaskqueue/lists"}